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")
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
推荐阅读
- c++ - 四叉树生成不完整类型
- mysql - Mysql INSERT ... ON DUPLICATE KEY Reinsert with new key
- python - 如何避免 Python 输入中的箭头键值?
- reactjs - 刷新页面时不需要返回登录?
- python - 如何在python for循环中就地转换值?
- java - 收集与多个 AWS 服务交互的 Java 应用程序的性能指标
- mxgraph - mxgraph 如何获取和设置边缘的标签位置?
- java - 如何在 android studio 中针对状态微调器加载城市微调器
- python-3.x - 为机器学习生成输入数据
- node.js - Nuxt 将代理页面呈现为 .gz 文件,但仅在部署中