Linux 简单Shell脚本编程

编写集成命令脚本,显示屏幕如下:

**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

这个程序我没有调试,只是给你个思路,你可以按照我的这个框架,自己调试一下,希望能帮到 你,谢谢!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-14
调试完毕:
#!/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;;
5) exit;;
*) echo illegal Option
esac
done
第2个回答  2009-11-14
这样

#! /bin/bash
while :
do
clear
cat<<-EOF

**cmd menu**

1 ---- date (Display today and current time)
2 ---- ls (List content of current directory)
3 ---- who (See who is on the system)
4 ---- pwd (Print the current directory)
5 ---- quit the menu

EOF

printf "Choice: "
read choice
case "$choice" in
1) echo "Today is $(date +%Y-%m-%d)"
echo "Now is $(date +%T)"
;;
2) ls
;;
3) who
;;
4) echo "We are in $(pwd)"
;;
5) break
;;
*) echo "I can't understand what you want?"
;;
esac
sleep 3
done
exit 0
# end script
相似回答