Connectors in the shell (and, and, or)

Source: Internet
Author: User

&& (and) with the || (OR) with the ; (and)

A semicolon has just been mentioned above for the delimiter between multiple commands. There are also two special symbols that can be used in the middle of multiple commands, that is, "&&" and "| |" are all listed below:

  1. command1 command2             Span style= "Font-size:18px;color:rgb (255,0,0); font-weight:bold;" > and

  2. command1 & & command2       and    

  3. Command1 || command2 or

&& : The left command executes successfully before executing the command on the right.

  || : The left command executes unsuccessfully to execute the command on the right.

; (semicolon) : The left command executes successfully, and the command behind it executes.

When using ";", Command2 will be executed regardless of whether Command1 is executed successfully;

When using "&&", only if the Command1 is executed successfully, Command2 will execute, otherwise command2 not execute;

When using "| |", the Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command to execute.

before doing the experiment, want to remove all the test*, but the deletion, but the prompt said that the authority is not enough, the following is the process of troubleshooting:

[[email protected] ~]# rm-rf test*rm: Cannot delete "Test2/test1": Insufficient permissions RM: Unable to delete "Test2/test3": Insufficient permissions RM: Unable to delete "Test2/test4": Insufficient authority [[email protected] ~]# ls test*test1  test3  test4[[email protected] ~]# lsattr test*----- A-------e-test2/test1----i--------e-test2/test3-------------e-test2/test4[[email protected] ~]# chattr-a Test2/test1[[email protected] ~]# chattr-i test2/test3[[email protected] ~]# rm-rf test*rm: Cannot delete "test2/ Test1 ": Insufficient permissions RM: Cannot delete" TEST2/TEST3 ": Insufficient permissions RM: Unable to delete" Test2/test4 ": Insufficient permissions [[email protected] ~]# ls test*test1  test3  test4[[email protected] ~]# ls-ld test*drwxrwxr-x 2 root root 4096 May  10 10:12 test2[[email protect Ed] ~]# ls-l test2/*-rw-r--r--1 root root 6 May  10 10:20 test2/test1-rw-r--r--1 root root 0 May  10 10:11 test 2/test3-rw-r--r--1 root root 0 May  10 10:12 test2/test4[[email protected] ~]# lsattr test2/*-------------e-tes T2/test1-------------e-test2/test3-------------e-tesT2/test4[[email protected] ~]# lsattr test2-------------e-test2/test1-------------e-test2/ Test3-------------e-test2/test4[[email protected] ~]# lsattr-d test2----i--------e-test2[[email  Protected] ~]# chattr-i test2/[[email protected] ~]# rm-rf test2/

If you have done the same experiment before, I believe you will have the same problem. The next step is to illustrate the role of the two special symbols "&&" and "| |" By doing experiments:

[[email protected] ~]# Touch test1 test3[[email protected] ~]# ls test2 && touch test2ls: Unable to access test2: No that file or directory [[EM AIL protected] ~]# ls test2ls: Cannot access test2: No file or directory [[email protected] ~]# ls test2 | | Touch TEST2LS: Unable to access test2: No file or directory [[email protected] ~]# ls test*test1 test2 test3


This article from "12350027" blog, declined reprint!

Connectors in the shell (and, and, or)

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.