shellscript-9-输入数字游戏
脚本内容
#!/bin/bash
# author: yolo
# 执行要求用户输入数字
# 当用户输入end停止输入
# 死循环
while :
do
# read 交互
read -p "请输入一个数字或者输入end结束:" n
# sed 's/[0-9]//g' 数字全部替换空
# wc -c 统计字符 回车也会标记为1
num=`echo $n | sed 's/[0-9]//g' | wc -c`
if [ $n == "end" ]
then
exit
fi
if [ $num -ne 1 ]
then
echo "请输入数字,重试"
else
echo "这个数字是:${n}"
fi
done