linux程序设计老师布置的作业:根据自己的写法和参考网上的
编一个shell 编写一个shell程序,使用shell编写一个菜单,分别实现列出以下内容:(1)目录内
容、(2)切换目录、(3)创建文件、(4)编辑文件、(5)删除文件的功能
#!/bin/sh
until
echo "1.目录内容"
echo "2.切换目录"
echo "3.创建文件"
echo "4.编辑文件"
echo "5.删除文件"
echo "6.退出菜单"
read input
test $input = 6
do
case $input in
1)ls;;
2)echo "enter target directory"
read dir
cd $dir;;
3)echo "enter a file name"
read file
touch $file;;
4)echo "enter a file name:"
read file
vi $file;;
5)echo "enter a file name"
read file
rm $file;;
6)echo "请输入选择(1-6)"
esac
done
另一种写法出自:http://wolfchen.blog.51cto.com/2211749/964615
#!/bin/bash
cat << EOF
********please enter your choise:(1-6)****
(1) List you selected directory
(2) Change to you selected directory
(3) Create a new file
(4) Edit you selected file
(5) Remove you selected file.
(6) Exit Menu.
EOF
read -p "Now select the top option to: " input
case $input in
1) ls;;
2) echo "Enter target directory:"
read dir
cd $dir;;
3) echo "Enter a file name:"
read file
touch $file;;
4) echo "Enter a file name:"
read file
vi $file;;
5) echo "Enter a file nmae:"
read file
rm $file;;
esac