One, for-done (not very common)
1. Grammar
For variable in name table do ... done
2. Script Sample Code
#!/bin/shfor num in 1 2 3 4 5do echo "number is $num" done
3. Execute script
[Email protected]]# sh hello.sh
4. Implementation results
The number is 1 the number is 2 the number is 3 the number is 4 the number is 5
Second, select (Not very common)
1. Grammar
Select variable in list do ... done
2. Script Sample Code
#!/bin/shselect fruit in "apple" "Pear" "peach" do Breakdoneecho "you chose $fruit"
3. Implementation results
1) Apple 2) Pear 3) Peach #? 1 //This place requires you to input your choice is Apple
Third, case
1. Grammar
Case variable in string 1) command list 1;; String 2) command List 2;; *) Command list 3esac
2. Script Sample Code
#!/bin/shread opcase $op in a) echo "you selected a";; b) echo "you selected B";; *) echo "Error" Esac
Four, while
1. Grammar
While [condition] //Note space do ... done
2. Script Sample Code
#!/bin/shnum=1while [$num-le]do num= ' expr $num + 1 ' doneecho $num
Shell Loop statement