我想让这个工作:
echo "Would you like to configure dns?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "you have selected to configure dns"; break;;
No ) exit; break;;
esac
done
我一直收到这个错误:
menu.sh:2:选择:未找到
menu.sh:7:语法错误:“完成”意外
先谢谢, 乔
答案 0 :(得分:12)
确保您在bash
中运行它,因为select
bash
理解sh
而不是{{1}}等一些shell。
答案 1 :(得分:0)
或者,只需使用while
,read
和case
重写即可。我认为select
并没有真正增加太多。
答案 2 :(得分:0)
这是我在这个论坛的帮助下写的一篇好文章:)
#!/bin/bash
while ["$yn" != "Yes" ]; do
echo "Choose your type of installation"
echo "1) Home Media Server"
echo "2) Home Communication Server"
echo "3) Enterprise Communication Server"
echo "4) Hosting Server"
echo "5) Individual Packages"
echo "6) exit"
read case;
#simple case bash structure
# note in this case $case is variable and does not have to
# be named case this is just an example
case $case in
1) echo "You have entered Home Media Server, is this correct? (Yes or No)"
read yn
echo "Running script for Home Media Server";;
2) echo "You have entered Home Communication Server, is this correct? (Yes or No)"
read yn
echo "Running script for Home Communication Server";;
3) echo "You have entered Enterprise Communication Server, is this correct? (Yes or No)"
read yn
echo "Running script for Enterprise Communication Server";;
4) echo "You have entered Hosting Server, is this correct? (Yes or No)"
read yn
echo "Running script for Hosting Server";;
5) echo "You have entered $hname, is this correct? (Yes or No)"
read yn
echo "Running script for Individual Packages";;
6) exit
esac