- #!/bin/sh
- #filename:b
- while :
- do
- echo "input a number:"
- read Val
- expr $Val + 1 > /dev/null 2>
- res=$?
- if [ "$Val" = "" ] || [ "$res" != "0" ]; then
- echo "what you input is not a number!"
- else
- echo "what you input is : $Val"
- break;
- fi
- done
注意: 在检测最后的命令状态的时候,$?必须先用一个变量保存,然后再去if 语句中进行条件比较.