shell 案例

1 while

#!/bin/bash
echo 'please input number'
read i
while [ $i -gt 50 ]
do
echo $i
((i--))
done

2 if --else   或者 if  ---  elif--- else  fi

echo "请输入一个路径"
read filename
if [ -f $filename ];then
echo "ok"
else
echo "no"
fi

3  case 

#!/bin/bash
echo "input command"
read cmd
case $cmd in
cpu) echo "cpu info:"
cat /proc/cpuinfo;;
mem) echo "mem info:"
cat /proc/meminfo;;
device) echo "divice info:"
cat /proc/scsi/device_info;;
*) echo "input command is not invalid"
esac

 

上一篇:03 输入输出、分支结构


下一篇:iptables控制