Linux 简单Shell脚本编程

来源:百度知道 编辑:UC知道 时间:2024/06/25 12:44:00
编写集成命令脚本,显示屏幕如下:

**cmd menu**
1----date
2----ls
3----who
4----pwd

choice::

要在choice后面输入一个数字,根据数字命令执行相应的命令。如果数字不在1―4的范围内,则显示出错信息。

回答经采纳给予加分!
http://zhidao.baidu.com/question/125464273.html
http://zhidao.baidu.com/question/125531507.html
http://zhidao.baidu.com/question/125531380.html
http://zhidao.baidu.com/question/125531264.html
http://zhidao.baidu.com/question/125464717.html

真是不知道怎么感谢你

echo "**cmd menu**"
echo "1----date"
echo "2----ls"
echo "3----who"
echo "4----pwd"

echo "choice::"
read number
if [ 1 == $number ];then
date;
if [ 2 == #number ]; then
ls;
if [ 3 == $number ];then
who;
if [ 4 == #number ]; then
pwd;

else
echo "you are wrong"
fi

这个程序我没有调试,只是给你个思路,你可以按照我的这个框架,自己调试一下,希望能帮到 你,谢谢!

调试完毕:
#!/bin/sh
until
echo date..........1
echo ls............2
echo who...........3
echo pwd...........4
echo exit..........5
echo Please input your choice:
read choice
test $choice = 5
do
case $choice in
1) date;;
2) echo Enter target directory
read dir
ls $dir
;;
3) who
;;
4) pwd;;