这是我正在使用的程序,但这是输出。
echo "Please select your favorite color"
echo " or 4 to exit"
echo "---------------------------------"
#set menu prompt
menu="select color : "
#set menu list
select menu in Blue Yellow Red Quit
do
case $menu in
Blue)
echo "----------------------------"
echo "Your favorite color is Blue!"
echo "----------------------------"
;;
Yellow)
echo "----------------------------"
echo "Your favorite color is Yellow!"
echo "----------------------------"
;;
Red)
echo "----------------------------"
echo "Your favorite color is Red!"
echo "----------------------------"
;;
Quit)
echo "----------------------------"
echo "Thank you!"
echo "----------------------------"
;;
*)
echo -e "Error: please try again (select 1......4)!"
esac
Please select your favorite color
or 4 to exit
./select.sh: line 36: syntax error: unexpected end of file
我该如何修复它?背景:我对 Linux 和编码还很陌生,所以我几乎不了解发生了什么。我 100% 是 YouTube 大学
编辑:#?4 错误:请重试(选择 1....4)!–
echo "Please select your favorite color"
echo " or 4 to exit"
echo "---------------------------------"
#set menu prompt
menu="select color : "
#set menu list
select menu in Blue Yellow Red Quit
do
case $menu in
Blue)
echo "----------------------------"
echo "Your favorite color is Blue!"
echo "----------------------------"
;;
Yellow)
echo "----------------------------"
echo "Your favorite color is Yellow!"
echo "----------------------------"
;;
Red)
echo "----------------------------"
echo "Your favorite color is Red!"
echo "----------------------------"
;;
Quit)
echo "----------------------------"
echo "Thank you!"
echo "----------------------------"
;;
*)
echo -e "Error: please try again (select 1......4)!"
esac
done
答案1
一般例子:
sudodus@bionic64 ~ $ select i in whoami "echo 'Hello World'" break;do $i;done
1) whoami
2) echo 'Hello World'
3) break
#? 1
sudodus
#? 2
'Hello World'
#? 3
sudodus@bionic64 ~ $
与您的问题匹配的示例:
一句话就足够了。
$ select i in Blue Yellow Red Quit;do if [ "$i" == "Quit" ];then break;else echo "Your favorite color is $i";fi;done
1) Blue
2) Yellow
3) Red
4) Quit
#? 1
Your favorite color is Blue
#? 2
Your favorite color is Yellow
#? 3
Your favorite color is Red
#? 4
$ select i in Blue Yellow Red Quit;do if [ "$i" == "Quit" ];then break;else echo "Your favorite color is $i";fi;done
1) Blue
2) Yellow
3) Red
4) Quit
#? 4
$
答案2
你的脚本应该是:
do
case $menu in
1) echo "----------------------------"
echo "Your favorite color is Blue!"
echo "----------------------------"
;;
2) echo "----------------------------"
echo "Your favorite color is Yellow!"
echo "----------------------------"
;;
3) echo "----------------------------"
echo "Your favorite color is Red!"
echo "----------------------------"
;;
4) echo "----------------------------"
echo "Thank you!"
echo "----------------------------"
exit
;;
*) echo -e "Error: please try again (select 1......4)!"
esac
done