、编写一个menu的shell脚本程序,有如下几行 Number Name For Linux Menu 1 exit leave menu or return 2 menu goto another local menu 3 vi deit a file 4 mail read a mai l 5 send send mail to someone 6 cal see your calendar . 7 who see who is on the system 8 ls list the fi les in this directory 9 cat display a file on the screen Please enter a number or a name for the action you wish: 要求具备清屏功能
时间: 2024-02-10 07:15:40 浏览: 105
Linux实现的shell脚本程序(大三写的大作业)
好的,这是一个简单的menu shell脚本程序,具备清屏功能:
```
#!/bin/bash
while true
do
clear
echo "For Linux Menu"
echo "1 exit leave menu or return"
echo "2 menu goto another local menu"
echo "3 vi deit a file"
echo "4 mail read a mail"
echo "5 send send mail to someone"
echo "6 cal see your calendar"
echo "7 who see who is on the system"
echo "8 ls list the files in this directory"
echo "9 cat display a file on the screen"
read -p "Please enter a number or a name for the action you wish: " choice
case $choice in
1 | exit)
break
;;
2 | menu)
echo "Going to another local menu..."
sleep 1
;;
3 | vi)
read -p "Please enter the file name you wish to edit: " filename
vi $filename
;;
4 | mail)
echo "Reading a mail..."
sleep 1
;;
5 | send)
read -p "Please enter the recipient's email address: " recipient
read -p "Please enter the subject of the email: " subject
read -p "Please enter the message you wish to send: " message
echo "Sending mail to $recipient with subject '$subject' and message '$message'..."
sleep 1
;;
6 | cal)
cal
;;
7 | who)
who
;;
8 | ls)
ls
;;
9 | cat)
read -p "Please enter the file name you wish to display: " filename
cat $filename
;;
*)
echo "Invalid choice. Please try again."
sleep 1
;;
esac
done
```
使用方法:
1. 将上述脚本粘贴到一个文件中,例如menu.sh。
2. 给该文件执行权限:`chmod +x menu.sh`。
3. 在终端中进入该文件所在目录,执行:`./menu.sh`。
4. 按照提示输入对应的数字或名称执行相应的操作,输入1或exit退出菜单。
阅读全文