在shell中使用while循环的例子
2008-12-03 11:44
387 查看
#!/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
#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
相关文章推荐
- shell下在while循环中使用ssh命令的问题
- shell中使用while循环ssh时只循环第一行的问题解决
- Shell-while循环的例子
- Shell脚本基础16-while循环中使用sleep命令
- shell中while循环里使用ssh的注意事项
- SHELLcase流程控制和for、while循环语句的使用
- shell中使用while循环ssh时只循环第一行的问题解决
- shell中使用while循环ssh的注意事…
- shell命令while循环中使用sleep命令代码示例
- 一个在HTML使用JavaScript实现调用Windows Shell.Application的例子。
- java-第五章-使用while循环输出:100,95,90..................
- 比较R语言、perl语言,matlab中for循环和while循环的使用
- Linux Shell系列教程之(十一)Shell while循环
- Linux shell for while 循环
- 14、C#里面的循环结构:while的使用
- JavaSE8基础 while循环中嵌套switch语句时,break语句的使用
- 编程作业50页3题 分别使用 do-while和 for 循环计算1+1/2!+1/3!+1/4!...+1/20!
- while循环语句的初步使用
- 循环语句的使用——while、do_while、for
- shell循环sleep while例子 条件判断