shell脚本中实现循环的方式

  1. 源码如下:
    • 1) 使用C语言风格版的for循环
#!/bin/bash
#the way of  circulation in  shell
#1.the c-style for circulation in linux
#for((i = 1;i < 10;i++))
#do 
#echo the current i is:$i
#done
  • 2) 使用while实现循环—-包括三种循环变量自增的方式
#the way 2 to do circulation
i=1
while [ $i -le 10 ]
do
echo the current i is :$i
let i++
#let i=$i+1
#let i=i+1 
#i=$[ $i + 1 ]
done
  • 3) 使用until实现循环
    需要注意的是:这里的until循环的终止条件是“当条件为真时,终止回话。”
#!/bin/bash
#using the until command
var1=1
until [ $var1 -eq 10 ]
do
echo $var1
let var1++
done