用shell来判断输入的是否是数字。
#cat isnum.sh
#!/bin/sh
file_size=128
echo "Please input a number for testing:"
read n
input_num="$(echo "$n" | sed -n "/^[0-9]\+$/p")"
if [ -n "$input_num" ];then
echo "Input is a number!"
file_size="$input_num"
echo "The number is: $file_size."
else
echo "Input isn't a number!"
echo "Use defaule number $file_size."
fi
阅读(846) | 评论(0) | 转发(1) |