linux shell编程之菜单选择(一)

来源:互联网 发布:2017淘宝美工工资待遇 编辑:程序博客网 时间:2024/05/22 15:29

linux程序设计老师布置的作业:根据自己的写法和参考网上的

编一个shell 编写一个shell程序,使用shell编写一个菜单,分别实现列出以下内容:(1)目录内
容、(2)切换目录、(3)创建文件、(4)编辑文件、(5)删除文件的功能

#!/bin/shuntilecho "1.目录内容"echo "2.切换目录"echo "3.创建文件"echo "4.编辑文件"echo "5.删除文件"echo "6.退出菜单"read inputtest $input = 6docase $input in1)ls;;2)echo "enter target directory"read dircd $dir;;3)echo "enter a file name" read file touch $file;; 4)echo "enter a file name:"read filevi $file;;5)echo "enter a file name"read filerm $file;;6)echo "请输入选择(1-6)"esacdone


另一种写法出自:http://wolfchen.blog.51cto.com/2211749/964615

#!/bin/bashcat << 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.EOFread -p "Now select the top option to: " inputcase $input in 1) ls;;2) echo "Enter target directory:"read dircd $dir;;3) echo "Enter a file name:"read filetouch $file;;4) echo "Enter a file name:"read filevi $file;;5) echo "Enter a file nmae:"read filerm $file;;esac


原创粉丝点击