eri*_*n00 0 ksh shell-script control-flow
这是我的脚本:
#!/bin/ksh
#this is where I want to go again if user enter
#an answer other than "yes or no"
echo "yes or no?"
read ans
case $ans in
[yY]*)
echo "yes"
;;
[nN]*)
echo "no"
;;
*)
echo "yes or no only"
# here, if the answer is not "Y" or "N",
# I want to go back to asking "yes or no?"
;;
esac
Run Code Online (Sandbox Code Playgroud)
谁能给我一个提示?
你可以把read
和你case
在一个while
循环,break
出来吧,当条件满足:
while : ; do
echo "yes or no?"
read ans
case $ans in
[yY]*)
echo "yes"
break
;;
[nN]*)
echo "no"
break
;;
*)
echo "yes or no only"
;;
esac
done
Run Code Online (Sandbox Code Playgroud)
该while : ; do ... done
代表无限循环。 break
退出for
, while
, 或until
循环。用于break
在答案为y
or 时退出n
,否则循环将继续。
归档时间: |
|
查看次数: |
9985 次 |
最近记录: |