Process Control Statements
In the shell if multiple commands are entered in the terminal, the commands are placed in the background if they are separated by &, and a collection of commands is represented if delimited. Shell allows logical operators to be used && and | | As the command delimiter, they separate when and and OR.
&&
If the previous command executes successfully, execute && the following command
||
If the previous command execution fails, execute | | The following command
If statement conditional Judgment statement
The IF statement is a judgment statement, based on the conditional execution command, in the following format:
if
The statement must fi
end with.
COMMANDS can be a single command, a command group, an expression. The IF statement executes the command according to their execution result or conditional expression.
Command
Executes the command based on the execution result (exit status) of the command.
If the exit status of LS equals 0
Command Group
When you need to execute multiple commands at once, you can execute them in groups, and command groups can be used (COMMANDS; ...). and {COMMANDS; ...;} To express.
Use parentheses (COMMANDS; ...) When the command is wrapped, the command executes in a child shell environment whose execution state is the execution state of the last command in commands.
Use curly braces {COMMANDS; ...;} To wrap the command, you must have a space before and after the parentheses, commands and commands to use; Separate, the execution state of the last command as the execution state of the command group.
Example:
If ...; Then ...; else ...; Fi statement
Use the If....else statement to execute code when the condition is true, and to execute additional code when the condition is false.
Grammar:
Example:
If ... else fi statement elif
Use the If....else if...else statement to select one of several code blocks to execute.
1 Linux Shell Programming (vii): Process Control statements