- #! /bin/sh
- #打印10以内的加法表
- i=1
- while [ $i -le 9 ]
- do
- row=1
- colume=$i
- while [ $row -le $i ]
- do
- if((i==9))
- then
- echo -n "$row+$colume=$((row+colume)) "
- else
- echo -n "$row+$colume=$((row+colume)) "
- fi
- row=$(expr $row + 1)
- colume=$(expr $colume - 1)
- done
- echo
- ((i=$i+1))
- done
0
下面这个脚本是判断一个输入的IP是否正确,正确则得到$webip ,错误则一直提示我们输入,一直到得到正确的IP为止。
- #! /bin/bash
- checkip() {
- if echo $1 |egrep -q '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$' ; then
- a=`echo $1 | awk -F. '{print $1}'`
- b=`echo $1 | awk -F. '{print $2}'`
- c=`echo $1 | awk -F. '{print $3}'`
- d=`echo $1 | awk -F. '{print $4}'`
- for n in $a $b $c $d; do
- if [ $n -ge 255 ] || [ $n -le 0 ]; then
- echo "the number of the IP should less than 255 and greate than 0"
- return 2
- fi
- done
- else
- echo "The IP you input is something wrong, the format is like 192.168.100.1"
- return 1
- fi
- }
- rs=1
- while [ $rs -gt 0 ]; do
- echo -n "Please input the webip(请输入web的IP):"
- read webip
- checkip $webip
- rs=`echo $?`
- done
编辑回复