Shell && vs | | Operator_bash

Source: Internet
Author: User
CMD1 && cmd2 If the command cmd1 result status 0, the CMD2 is executed, otherwise the CMD2 command is not executed.
cmd1 | | CMD2 if the command cmd1 result status 1, the CMD2 is executed, otherwise the CMD2 command is not executed.
can be used for exception handling:
I.e: Run the CMD1 command and output a message if the CMD1 is running wrong.
Adb-s "Device" Logcat | | {echo "Device not found"; exit 1;}

Explanation: If the command adb-s "device" Logcat execute an error, the user is prompted to "device not found."

i.e:
As the following command:
[[E File1]] && echo "file1 file exits." | | Touch File1

The first time the command is executed, the result status of the [[E-file1] command is 1 when there is no file1 file under the current command, and the command echo "File1 file exits" is not executed, and for the Touch file1 command, due to the previous Action ([[E File1]] && echo "file1 file exits." The result status is 1, so the touch file1 is executed

But when the command is run the second time, the [[E-file1]] command returns 0, then the echo "File1 file exits" is executed without performing the touch file1 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.