熟悉判断.read ,是否整数,等表达式
#!/bin/basa a=$1 b=$2 #read -p "qingshuru:" a b #no1 [ -z "$a" ] || [ -z "$b" ] &&{ echo "shanshu bu gou" exit 1 } #no2 expr $a + 0 &>/dev/null DD1=$? expr $b + 0 &>/dev/null DD2=$? test $DD1 == 0 || $DD2 == 0||{ echo "qing shuru zheng shu!" exit 2 } #no3 [ $a -lt $b ] &&{ echo "$a < $b" exit 0 } [ $a -gt $b ] &&{ echo "$a > $b" exit 0 } [ $a -eq $b ] &&{ echo "$a = $b" exit 0 }
菜单模拟
#!/bin/sh menu(){ cat <<EOF 1.install LAMP 2.install LNMP 3.exit pls input EOF } menu read -p "qing shu ru :" -t 15 a [ $a -eq 1 ]&&{ echo "ni xuan zhe le LAMP" sleep 3 echo "starting LAMP" } [ $a -eq 2 ]&&{ echo "ni xuan zhe le 2 LNMP" sleep 3 echo "starting LNMP" } [ $a -eq 3 ]&&{ echo "ni xuan zhe le exit" exit 0 } [ ! $a -eq 1 -o ! $a -eq 2 -o ! $a -eq 3 ]&&{ echo "shu ru bu dui !" exit 1 } 例子2 menu1(){ cat <<END ***************************** 1.[install lamp] 2.[install lnmp] 3.[exit] pls input the num you want: ***************************** END } menu2(){ cat <<END =================================== 1.[install apache] 2.[install php] 3.[install mysql] 4.[back] pls input the 2 menu num you want: =================================== END } menu1 read num [ $num -eq 1 ] &&{ menu2 read num2 [ $num2 -eq 1 ] &&{ echo "start installing apache." exit } }
数值大小比较
#!/bin/basa if [ -z "$1" -o -z "$2" ] then echo "mei you shu ru!!!!!" exit 1 fi expr $1 + 0 &>/dev/null DD1=$? expr $2 + 0 &>/dev/null DD2=$? test $DD1 -eq 0 -a $DD2 -eq 0||{ echo "shu ru cuo wu!" exit 2 } if [ $1 -gt $2 ];then echo "$1 > $2" elif [ $1 -lt $2 ];then echo "$1 < $2" elif [ $1 -eq $2 ];then echo "$1 = $2" fi
停留在世界边缘,与之惜别