我如何有更多选择来回答这个问题?
while [ "$yn" != "Yes" ]; do
echo "Please enter your Host Name"
read hname
echo "You have entered $hname, is this correct? (Yes or No)"
read yn
done
sh runscript.sh
想回答“是”“是”“Y”或“y”,怎么办? 提前致谢, 乔
答案 0 :(得分:6)
while [ -z "$yn" ]
do
read -p "Please enter your Host Name" hname
read -p "You have entered $hname, is this correct? (Yes or No)" yn
case $yn in
Y|y|Yes|yes);; # this is a no-op
*) unset yn;;
esac
done
答案 1 :(得分:1)
与其他任何语言一样,Bash也有逻辑运算符。你可以用Bash创建这样的东西(这是伪代码):
If answer equals "Yes", or answer equals "yes":
bla bla
我建议你查找一个Bash教程,你会发现它还有更多! 欢呼声。
答案 2 :(得分:0)
修正了它!认为这最有效:
while [[ "$yn" != "Yes" && "$yn" != "Y" && "$yn" != "y" && "$yn" != "yes" ]]; do
耶!