table of Contents
1. Use double parentheses conditional expression
[qinys@localhost 20200313]$ cat 02_reverse.sh
#!/bin/bash
i=10
while ((i>0)) # 使用(())
do
echo $i
((i--))
done
Print Results:
[qinys@localhost 20200313]$ sh 02_reverse.sh
10
9
8
7
6
5
4
3
2
1
2. Use double brackets conditional expression
[qinys@localhost 20200313]$ cat 02_reverse_1.sh
#!/bin/bash
i=10
while [[ $i>0 ]]
do
echo $i
((i--))
done
Print Results:
[qinys@localhost 20200313]$ sh 02_reverse_1.sh
10
9
8
7
6
5
4
3
2
1
3. Use a single conditional expression in parentheses
[qinys@localhost 20200313]$ cat 02_reverse_2.sh
#!/bin/bash
i=10
while [ $i -gt 0 ]
do
echo $i
((i--))
done
Print Results:
[qinys@localhost 20200313]$ sh 02_reverse_2.sh
10
9
8
7
6
5
4
3
2
1
4. Use the command until
[qinys@localhost 20200313]$ cat 02_reverse_3.sh
#!/bin/bash
i=10
until [[ $i < 1 ]]
do
echo $i
((i--))
done
Print Results:
[qinys@localhost 20200313]$ sh 02_reverse_3.sh
10
9
8
7
6
5
4
3
2
1