Linux Shell several special symbols Command &, &&, | |

Source: Internet
Author: User

    1. & placed after the startup parameter to set this process as a background process

By default, the process is the foreground process, then the shell is occupied, we can not do other operations, for those who do not interact with the process, many times, we want to start in the background, you can start the parameters with a ' & ' to achieve this purpose.

2. && | |

When the shell executes a command, it returns a return value that is saved in the shell variable $? In When $? = = 0 o'clock, indicating successful execution; = = 1 O'Clock (I think the number is 0 and the return value is 0-255), indicating that the execution failed.

Sometimes the next command depends on whether the previous command succeeds. For example, execute another command after executing a command successfully, or execute another command after a single command fails. The shell provides && | | To implement command execution control, the shell will be based on && or | | The return value of the preceding command to control the execution of subsequent commands.

The syntax format is as follows:

Command1 && command2 [&& Command3 ...]

1 use && Connect between commands to achieve
Logic with the function.

2 only the command on the left of && returns True (command return value $?). = = 0) The command to the right of,&& will be executed.

3 As long as there is a command return False (command return value $?) = = 1), the subsequent command will not be executed.

Logical OR function

Command1 | | Command2 [| | Command3 ...]

1 Use between commands | | Connect, implement
Logical OR function.

2 Only in | | The left command returns False (the command returns a value of $?). = = 1), | | The command on the right will not be executed. This is the same as the logical or syntactic function in C, which is to implement short-circuit logic or operations.

3 As long as there is a command return True (command return value $?) = = 0), the subsequent command will not be executed. – Stop execution until it returns to the real place.

Linux Shell several special symbols Command &, &&, | |

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.