设计如下一个菜单驱动程序
Use one of the following options:
P:To display current directory
S:To display the name of running file
D:To display today's date and present time (要求显示为:2017-04-26 05:45:12)
L:To see the list of files in your present working directory
W:To see who is logged in
Q:To quit this program
Enter your option and hit:
菜单程序将根据用户输入的选择项给出相应信息。要求对用户的输入忽略大小写,对于无效选项的输入给出相应提示。要求使用case语句实现以上功能,输入相应的字母后应该执行相应的命令完成每项功能,如输入P或p,就执行pwd命令。
#!/bin/bash function welcome() { echo -e " " echo "Use one of the following options:" echo "P: To display current derectory " echo "S: To display the name of running file" echo "D: To display today's date and present time" echo "L: To see the listing of files in your present working directory" echo "W: To see who is logged in" echo "Q: To quit this program" echo -n "Enter your option and hit:" read a echo -e " " } welcome until [ $a = q -o $a = Q ]; do case "$a" in p|P) pwd welcome ;; s|S) echo "The running file is $0" welcome ;; d|D) date welcome ;; l|L) ls -a welcome ;; w|W) who welcome ;; *) echo -n "Sorry,your option is wrong,please enter your option again" echo -e " " read a esac done echo "Thank you for your playing" exit 0