Process control

【if statement 】

Condition1 then command1 elif condition2 then command2 else commandN fi

Fi ends an if statement, equivalent to endif

Elif [$a -gt $b] then echo "a < b" elif [$a -gt $b] then echo "a < b" elif [$a -lt $b] then echo "a < b" elif [$a -lt $b] then echo "a < b" elif [$a -lt $b] then echo "a < b" elif [$a -lt $b] then echo "a < b" elif [$a -lt $b] then echo "A < b" Else echo "No criteria met" fiCopy the code

Note: there must be Spaces before and after the “[” symbol

【case statement 】

Syntax case value in Mode 1) command1;; Mode 2) commandN; esac

Echo "input your name:" read name case $name in zhanghe) echo "; A: who are you, zhangsan? *) echo "I don't know you "; esacCopy the code

  • I have to put in after this
  • The value of the variable matches the string before the) symbol
  • If a match is found, the statement under that case is executed until it is found. When to stop
  • If there is no match, the last *) line is executed
  • If there is no match and you don’t want to do anything, don’t write *)

1. Be sure to pay attention to; If you don’t add; The execution will be wrong


In the previous section Linux command (4) operating files in the next section Linux command (6) loop statement