例一:
函数、返回状态值、比较
#!/bin/bashNUM=$(date +%S)echo "当前苹果价格是每斤$NUM元"echo "========================"sleep 1clearipple(){echo '这苹果多少钱一斤啊? 请猜0-60的数字'read -p "请输入你的价格:" Aexpr $A + 1 &>/dev/nullif [ $? -ne 0 ] then echo "别逗我了,快猜数字" ipplefi}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/bashNUM=$(date +%S)echo "当前苹果价格是每斤$NUM元"echo "========================"sleep 1clearipple(){echo '这苹果多少钱一斤啊? 请猜0-60的数字'read -p "请输入你的价格:" Aexpr $A + 1 &>/dev/nullif [ $? -ne 0 ] then echo "别逗我了,快猜数字" ipplefi}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(){ipplewhile truedo guessdone}mai