1.使用雙小括號條件表達式
[qinys@localhost 20200313]$ cat 02_reverse.sh
#!/bin/bash
i=10
while ((i>0)) # 使用(())
do
echo $i
((i--))
done
打印結果:
[qinys@localhost 20200313]$ sh 02_reverse.sh
10
9
8
7
6
5
4
3
2
1
2.使用雙中括號條件表達式
[qinys@localhost 20200313]$ cat 02_reverse_1.sh
#!/bin/bash
i=10
while [[ $i>0 ]]
do
echo $i
((i--))
done
打印結果:
[qinys@localhost 20200313]$ sh 02_reverse_1.sh
10
9
8
7
6
5
4
3
2
1
3.使用單中括號條件表達式
[qinys@localhost 20200313]$ cat 02_reverse_2.sh
#!/bin/bash
i=10
while [ $i -gt 0 ]
do
echo $i
((i--))
done
打印結果:
[qinys@localhost 20200313]$ sh 02_reverse_2.sh
10
9
8
7
6
5
4
3
2
1
4.使用until命令
[qinys@localhost 20200313]$ cat 02_reverse_3.sh
#!/bin/bash
i=10
until [[ $i < 1 ]]
do
echo $i
((i--))
done
打印結果:
[qinys@localhost 20200313]$ sh 02_reverse_3.sh
10
9
8
7
6
5
4
3
2
1
