admin 发表于 2014-4-17 11:48:24

Bash While Loop

This topic is about the While Loop on Unix/Linux bash environment.Following is the sample:

while [ condition ]
do
    command1
    command2
    command3
    if [ condition ]
       command1
    fi
done


-------------------------
#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done

-------------------------
result will be like this:

Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times

页: [1]
查看完整版本: Bash While Loop