shell中使用while循环方法

#!/bin/sh
#filename:2.sh
b=9
e=15
tmpb=$b
while [ $tmpb -le $e ]
do
  echo $tmpb
  #tmpb=`expr $tmpb + 1`  //ok
  tmpb=$(expr $tmpb + 1)
done
执行这个脚本后,输出的结果为:

9
10
11
12
13
14
15


注意:   第9行的功能和第10行的功能是一样的。

下面的例子是使用一个循环,必须输入一个数字才能退出.

#!/bin/sh
#filename:b

while :
do
  echo -n “input a number:”
  read Val
  expr $Val + 1 > /dev/null 2>
  res=$?
  if [ "$Val" = "" ] || [ "$res" != "0" ]; then
     echo “what you input is not a number!”
  else
    echo “what you input is : $Val”
     break;
  fi
done
参与0

0同行回答

“答”则兼济天下,请您为题主分忧!

提问者

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2010-10-28
  • 关注会员:0 人
  • 问题浏览:5736
  • X社区推广