wer21213 发表于 2015-6-10 10:13:55

while循环 case语句 的一个脚本

小脚本:
执行效果 显示一个菜单 当输出菜单上给出的键后,执行相应的动作
即 当用户输出d 显示 show disk usages. 当然这也可以真的显示disk使用情况,只是加入的命令的不同,哈哈,,,这个是个人自己编写的,,看老师给出的题目。

# cat choice.sh
#!/bin/bash

echo "(d|D) shwo disk usages."
echo "(m|M) show memory usages."
echo "(s|S) show swap usages."
echo "(qQ) quit"
echo "(p) print this menu"
read -p "input options: " INSOME
while [ $INSOME != 'quit' ]; do
case $INSOME in
    )
       echo " show disk ussage"
      read -p "input options: " INSOME;;
    )
       echo "show memory usage"
      read -p "input options: " INSOME;;
    )
       echo "show swap usages"
       read -p "input options: " INSOME;;
    )
       echo "quiting..."
       exit 0;;
    p)
       echo "(d|D) shwo disk usages."
       echo "(m|M) show memory usages."
       echo "(s|S) show swap usages."
       echo "(qQ) quit"
       read -p "input options: " INSOME;;
    *)
       echo "Unknown character."
       read -p "input options: " INSOME;;
   esac
done

#


页: [1]
查看完整版本: while循环 case语句 的一个脚本