shell 程式設計入門 比較兩個數的大小
阿新 • • 發佈:2018-12-23
shell 程式設計入門
#!/bin/sh #The function used to compare the two numbers vara=$1 varb=$2 if [ -z $vara ] || [ -z $varb ] then echo "please input hte two numbers" exit 1 fi if [ $vara -eq $varb ] ; then echo "the $vara = $varb" else if [ $vara -gt $varb ] then echo "the $vara > $varb" elif [ $vara -lt $varb ] then echo "the $vara < $varb" fi fi
[[email protected] sourcetemp]# ./compare 1 2
the 1 < 2
[[email protected] sourcetemp]# ./compare 4 3
the 4 > 3
[[email protected] sourcetemp]# ./compare 3 3
the 3 = 3
需要注意的:
1.#!/bin/bash 寫成 #!bin/bash 找不到解析
2.#!/bin/bash 可寫成 #!/bin/sh sh 連線到 bash
3.if [ $var -eq $varb ] ; then
都有空格