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

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


  • 1
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值