1 Linux Shell Programming (vii): Process Control statements

Source: Internet
Author: User
Tags logical operators

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:

ifThe 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.