#腳本編輯
#!/bin/bash
#定義變量
num1=$1
num2=$2
num2=$2
#判斷是否輸入兩個參數,若是,將兩個參數傳遞給下一個指令動作,若非兩個參數,則打印輸出內容輸出並且退出exit腳本不執行下一個指令
if [ $# -ne 2 ] ;then
echo 'please input num1 & num2:'
exit
fi
if [ $# -ne 2 ] ;then
echo 'please input num1 & num2:'
exit
fi
#以上判斷后,輸入的兩個參數將傳遞到如下指令判斷
if [ $num1 -gt $num2 ] ; then
echo $num1 great than $num2
if [ $num1 -gt $num2 ] ; then
echo $num1 great than $num2
else if [ $num1 -lt $num2 ] ; then
echo $num1 less than $num2
else
echo $num1 equal $num2
echo $num1 equal $num2
fi
fi
fi
#驗證是否正確
[root@lin scripts]# sh compare2.sh 66
please input num1 & num2:
[root@lin scripts]# sh compare2.sh 10 10
10 equal 10
[root@lin scripts]# sh compare2.sh 10 1
10 great than 1
[root@lin scripts]# sh compare2.sh 10 50
10 less than 50
[root@lin scripts]# sh compare2.sh 6 7 8 9 10
please input num1 & num2: