&& in Linux shell | | and ()

Source: Internet
Author: User

1. Introduction of the Linux command return value

When the shell executes a command, it has a return value that is stored in the shell variable $?. When $? is 0 o'clock, the command execution succeeds; when $ = 1 o'clock, the command execution fails.

2. &&

The syntax format is as follows:

Command1 && command2 && ...

    • Use && connection between command to implement logic and function
    • The command on the right side of,&& will be executed when the commands on the left side of && execute successfully (command return value $?=0).
    • As long as a command execution is unsuccessful (command return value $?=1), subsequent command will not be executed

3. | |

The syntax format is as follows:

Command1 | | Command2 | | .....

    • Use between command | | Link to implement logic or functionality
    • When | | The left command execution is unsuccessful (command return value $?=1), | | The command on the right will be executed.
    • As long as there is a command execution Success (command return value $?=0), subsequent command will not be executed.

4 ()

The syntax format is as follows:

(Command1;command2; ...)

    • A command needs to have a single physical row, and if multiple comand need to be placed on the same line, the command delimiter (;) delimited) is required between the commands. The effect of execution is equivalent to multiple separate commands executed separately.
    • () indicates that multiple command executions are performed as a whole in the current shell. Note: Thecommand combination is executed under the current working directory, although the command has the command to switch directories.
    • command combination often commands execution control (&& or | |) Used in combination.

&& in Linux shell | | and ()

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.