如何在选择一个选项后让bash菜单程序不退出

时间:2018-04-30 20:38:20

标签: bash shell utility

我有一个可以正常工作的程序,但我需要它在做出选择后不退出。理想情况下,在做出一个选择后,命令将执行,然后菜单将弹出,要求用户输入另一个选项。我知道我需要使用某种循环来实现这一目标,但是我对于编写脚本非常新,并且无法在我的书中找到很多帮助。以下是我到目前为止的情况:

#!/bin/bash
#create the menu
echo -e "\n     MENU\n"
echo " a. Current date and time"
echo " b. Users logged in"
echo " c. Name of working directory"
echo " d. Create file with a custom name"
echo -e " e. Exit the program \n"
read -p "Enter a, b, c, d, or e: " answer
echo
#read input and perform utility
case "$answer" in
a)
date
;;
b)
who
;;
c)
pwd
;;
d)
read -p "Enter a name for your file " file
touch "$file"
;;
e)
exit
;;
*)
echo "$answer is not an option"
;;
esac

0 个答案:

没有答案