For loop
1. Note Do must wrap
For i in {1..10} do echo $idone
2. Note Do must wrap
For I in 1 2 3 4 5 do echo $idone
3. Traverse the results of the command output
For shname in ' ls *.sh ' do echo $shnamedone
4. For loops similar to high-level languages
For ((i=1;i<100;i++)) do echo $idone
The For loop is here, and these are enough.
While loop
Min=1max=100while [$min-le $max]do echo $min min= ' expr $min + 1 ' done
[] In the conditional expression,-le is less than equals, more can refer to the comparison operator
Until cycle
Min=0max=100until [$min-ge $max]do min= ' expr $min + 1 ' echo $mindone
If judgment, note the space
1. If
value=1if [$value-eq 1]; Then echo "true" fi
2. If...else
value=80if [$value-lt];then echo "fail" else echo "Success" fi
3. If...elif...else
value=80if [$value-lt];then echo "fail" elif [$value-ge];then echo "good" else echo "Success" fi
4. && | | Operation
value=80if [$value-ge 0] && [$value-le];then echo "ok" fi
Arithmetic expressions (for add, subtract, multiply, divide, take-up)
Expr expression
i=1i= ' expr $i + 1 ' echo $ii =$ (expr $i-1) echo $i
Let expression
I=10let i= $i +1echo $ilet i*=2echo $i
Using declare
Declare-i numnum= $num +1echo $num
$ ((expression))
i=2i=$ ((i+1)) echo $i
Linux Shell Basic Learning--cycle and condition judgment