Bash shell

例一:

函数、返回状态值、比较

#!/bin/bash
NUM=$(date +%S)
echo "当前苹果价格是每斤$NUM元"
echo "========================"
sleep 1
clear

ipple(){
echo '这苹果多少钱一斤啊?
      请猜0-60的数字'
read -p "请输入你的价格:" A
expr $A + 1 &>/dev/null
if [ $? -ne 0 ]
 then
        echo "别逗我了,快猜数字"
        ipple
fi
}


guess(){
        if [ $A -eq $NUM ]
         then
                echo "猜对了,就是$NUM元"
                exit 0
         elif [ $A -gt $NUM ]
          then
                echo "嘿嘿,要不你用这个价买?"
                ipple
         elif [ $A -lt $NUM ]
          then
[root@A11-11 mnt]# vi apple.sh    
#!/bin/bash
NUM=$(date +%S)
echo "当前苹果价格是每斤$NUM元"
echo "========================"
sleep 1
clear

ipple(){
echo '这苹果多少钱一斤啊?
      请猜0-60的数字'
read -p "请输入你的价格:" A
expr $A + 1 &>/dev/null
if [ $? -ne 0 ]
 then
        echo "别逗我了,快猜数字"
        ipple
fi
}


guess(){
        if [ $A -eq $NUM ]
         then
                echo "猜对了,就是$NUM元"
                exit 0
         elif [ $A -gt $NUM ]
          then
                echo "嘿嘿,要不你用这个价买?"
                ipple
         elif [ $A -lt $NUM ]
          then
                echo "太低太低"
                ipple
         fi
}

main(){
ipple
while true
do
  guess
done
}
mai

 

posted @ 2015-09-28 10:13  kin2321  阅读(179)  评论(0编辑  收藏  举报