Bash 选择菜单的行为与预期不符
我对bash还不熟悉。我想在bash中有一个选择菜单。它有四种选择。代码如下:Bash 选择菜单的行为与预期不符,bash,Bash,我对bash还不熟悉。我想在bash中有一个选择菜单。它有四种选择。代码如下: #!/bin/bash PS3='Please enter your choice: ' while true; do clear options=("Option 1" "Option 2" "Option 3" "Exit") select opt in "${options[@]}" do case $opt in "Option 1")
#!/bin/bash
PS3='Please enter your choice: '
while true; do
clear
options=("Option 1" "Option 2" "Option 3" "Exit")
select opt in "${options[@]}"
do
case $opt in
"Option 1")
echo "you chose choice $REPLY which is $opt"
break
;;
"Option 2")
echo "you chose choice $REPLY which is $opt"
break
;;
"Option 3")
echo "you chose choice $REPLY which is $opt"
firefox http://localhost:8000/browser/
break
;;
"Exit")
break 2
;;
*) echo "invalid option $REPLY";;
esac
done
read -p "Press [Enter] key to continue..."
done
以下是输出:
1) Option 1
2) Option 2
3) Option 3
4) Exit
Please enter your choice: 1
#you chose choice 1 which is Option 1
Press [Enter] key to continue...
这段代码运行得非常好,除非我按3。在这种情况下,在打印我想要的消息后,使用以下命令打开浏览器:
firefox http://localhost:8000/browser/
打开浏览器后,我希望我的代码显示以下消息:
Press [Enter] key to continue...
但直到我关闭浏览器,它才生效。怎么了
怎么了
伟大的代码
如果您想在后台运行进程firefox
,只需在命令末尾添加&
echo "you chose choice $REPLY which is $opt"
firefox http://localhost:8000/browser/ &
break
怎么了
伟大的代码
如果您想在后台运行进程firefox
,只需在命令末尾添加&
echo "you chose choice $REPLY which is $opt"
firefox http://localhost:8000/browser/ &
break
那么你想与脚本同时运行firefox?我想让脚本打开浏览器,然后显示“按[Enter]键继续…”作为选项1和选项2。那么你想让浏览器和进程同时运行。那么你想与脚本同时运行firefox?我想让脚本打开浏览器,然后显示“按”[输入]键继续…”作为选项1和选项2。因此,您希望浏览器和进程同时运行。