Bash脚本:始终显示循环执行后菜单 [英] Bash script: always show menu after loop execution
本文介绍了Bash脚本:始终显示循环执行后菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这样的bash脚本菜单:
I'm using a bash script menu like this:
#!/bin/bash
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1")
echo "you chose choice 1"
;;
"Option 2")
echo "you chose choice 2"
;;
"Option 3")
echo "you chose choice 3"
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
在每个菜单选择我只是得到提示
After each menu selection I just get prompted with
Please enter your choice:
我怎么一直显示后,每个选项执行结束菜单吗?我做了一些环顾四周,我想我可以做一些while循环,但我一直没能得到任何工作。
How do I always show the menu after each option has finished execution? I've done some looking around and I think I can do some kind of while loop, but I haven't been able to get anything working.
推荐答案
请它美丽而用户友好的; - )
Make it beautiful and userfriendly ;-)
#!/bin/bash
while :
do
clear
cat<<EOF
==============================
Menusystem experiment
------------------------------
Please enter your choice:
Option (1)
Option (2)
Option (3)
(Q)uit
------------------------------
EOF
read -n1 -s
case "$REPLY" in
"1") echo "you chose choice 1" ;;
"2") echo "you chose choice 2" ;;
"3") echo "you chose choice 3" ;;
"Q") exit ;;
"q") echo "case sensitive!!" ;;
* ) echo "invalid option" ;;
esac
sleep 1
done
在这个例子中替换回声与函数调用或调用其他脚本。
Replace the echos in this example with function calls or calls to other scripts.
这篇关于Bash脚本:始终显示循环执行后菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文