首页 > 代码库 > bash新手if语句实现三个数比较大小

bash新手if语句实现三个数比较大小

#!/bin/bash
if [ $# -ne 3 ];then
  echo "Usage: ./compare.sh ARG1 ARG2 ARG3"
  exit 1
fi

if [ $1 -gt $2 ];then
  if [ $1 -gt $3 ];then
     if [ $2 -gt $3 ];then
       echo "$1 > $2 > $3"
     else
       echo "$1 > $3 > $2"
     fi
  else
    echo "$3 > $1 > $2"
  fi
elif [ $2 -gt $3 ];then
  if [ $1 -gt $3 ];then
    echo "$2 > $1 > $3"
  else
    echo "$2 > $3 > $1"
  fi
else
  echo "$3 > $2 > $1"
fi


bash新手if语句实现三个数比较大小