Shell Script Raiders (learning notes)--1.3 Command logical execution order

Source: Internet
Author: User

You can use the semicolon ";", the double ampersand "&&" and the Double vertical bar "| |" in Linux To connect multiple commands.

1.3.1 Semicolon;

When multiple commands want to be executed at the same time on a single line, a semicolon ";" can be used after each command. There is no logical relationship between multiple commands, and all commands written are executed, even if a command has errors and does not affect other commands.

ls das; Echo " Hdakl "

Ls:cannot access das:no such file or directory

Hdakl

1.3.2 &&

Logic and. Command1 && Command2, Command2 is executed only if Command1 is executed correctly, Command1 is not performed if Command2 is not executed correctly. How to judge correctly, bash internal will pass the predefined variable "$?" To judge.

Echo " Hdakl " ls

Hdakl

Ls:cannot access ds:no such file or directory

ls Echo " Hdakl "

Ls:cannot access das:no such file or directory

1.3.3 | |

Logical OR. Command1 | | Command2, Command2 will not be executed unless Command1 is executed correctly command2,command1 execution is performed correctly. | And && are short-circuiting symbols, which have a logical relationship between the commands around the symbol.

ls Echo " Hdakl "

Ls:cannot access das:no such file or directory

Hdakl

Echo " Hdakl " ls ds   

Hdakl

general use of && and | | , it's basically logical and logical, or :command1 && Command2 | | Command3. Because in practice, Command2 and Command3 should all be commands that you want to execute. If Command1 is executed correctly, $? equals 0, executes Command2, and then the situation executes Command3, if the Command1 error executes, $? is not equal to 0, does not execute Command2, but then according to this non-0, judged the | | The right side should be executed.

Shell Script Raiders (learning notes)--1.3 command logical execution order

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.