写一个脚本,执行后,打印一行提示“Please input a number:”,要求用户输入数值,然后打印出该数值,然后再次要求用户输入数值。直到用户输入”end”停止。
参考答案:
#!/bin/bash
while :
do
read -p "Please input a number:(end for exit) " n
num=` echo $n |sed -r 's/[0-9]//g'|wc -c `
if [ $n == "end" ]
then
exit
elif [ $num -ne 1 ]
then
echo "what you input is not a number!Try again!"
else
echo "your input number is: $n"
fi
done
shell习题
shell习题-用户交互脚本
2017年8月17日
shell习题
No Comments
aming
写一个脚本,执行后,打印一行提示“Please input a number:”,要求用户输入数值,然后打印出该数值,然后再次要求用户输入数值。直到用户输入”end”停止。
参考答案:
shell习题