flag=true
read -p "please input a number:" num
while $flag
do
expr $num + 0 >/dev/null
[ $? -eq 0 ] flag=false || read -p "please input a integer:" num
done
2、通过sed来判断
flag=true
read -p "please input a number:" num
while $flag
do
len=`echo "$num"|sed 's/[0-9]//g'|sed 's/-//g'`
[ -n $len ] flag=false || read -p "please input a integer:" num
done