运行Shell脚本,首先显示类似如下的菜单:
What would you like to do:
List Directory **********************1
Change Directory*********************2
Edit file****************************3
Remove file**************************4
Add messages in a file***************5
Search keyword in a specified file***6
Sorting on a specified field*********7
Exit Menu****************************8
Enter your choice:
注意:该菜单要能够反复显示,即各项选完后要能再次返回菜单。
2.按1:以长格式列出当前目录内容。
3.按2:改变工作目录到自己指定的目标目录中。(改变后可以用选项1查看该目录中的内容)
4.按3:提示输入一个文件名(该文件可能不存在),然后调用vi编辑器进行编辑。
5.按4:删除一个指定的文件。
6.按5: 提示输入一个文件名,然后将用户在键盘上命令行方式下输入的任何信息都添加并保存到这个文件中,直到用户输入一个结束标志符(如一个空行)后才完成该项操作。
注意:该操作不能是只输入一行后就停止,要能不断输入多行信息;不能调用vi编辑器来输入。
例如:一个名为”phone”的文件,原有内容为(也可以是无内容的新文件):
“ This is a phone list”
现在要在其后添加一些电话薄的字段信息,
选择“5”后,显示:Input the filename that you want to add messages:
然后从键盘输入文件名:phone
接着提示:输入要添加的信息,例如用户要添加如下信息:
David Brown (7771) 91101111 m@m.com …………
Emma Redd (6970) 22292222 in@o.com ………..
Tom Swanson (823) 44474444 ai@e.com ………..
Ming Li (0871) 3133333 bb@r.com ………..
……………. …… …….. ………… ………..
输入完成后,按某个标志键退出该选项。该”phone”文件添加后变为:(可以用选项3查看)
This is a phone list
David Brown (7771) 91101111 m@m.com …………
Emma Redd (6970) 22292222 in@o.com ………..
Tom Swanson (823) 44474444 ai@e.com ………..
Ming Li (0871) 3133333 bb@r.com ………..
……………. …… …….. ………… ………..
源程序:
until
echo ****************What would like to do*************
echo ****************List Directory*******************1
echo****************ChangeDirectory*****************2
echo ****************EditFile************************3
echo****************RemoveFile**********************4
echo ****************Add messages in a File***********5
echo ****************Sreach keyword in a specified****6
echo ****************Sorting on a specified file******7
echo****************ExitMenu************************8
read choice
test $choice = 8
do
case $choice in
1) ls -l;;
2) echo Enter target directory
read dir
cd $dir
;;
3) echo Enter file name
read file
vi $file
;;
4) echo Enter file name
read file
rm $file
;;
5) echo Enter the messages
cat >> phone.list
wq phone.list
;;
6) echo Enter file name
sort phone.list
;;
7)echo Enter file name
read file
ls -x
;;
q|Q|8) echo Goodbye;;
*) echo illegal Option
esac
done
:help :help :help :help :help