Three special semicolons are used for command judgment (;),&&,||

(1). A semicolon (;)

Regardless of the relevance of the command , Continuous execution , There is no guarantee that all commands will be executed successfully .

example :

1

2

3

[[email protected] ~]# ls xxxx ; echo aaaa

ls: cannot access xxxx: There is no file or directory

aaaa

(2).&&

Logic and , Only when the previous command is executed successfully , To execute the later order

example :

1

2

3

4

5

[[email protected] ~]# ls /opt

rh

[[email protected] ~]# cd /opt/ && touch a && ls

a  rh

[[email protected] opt]#

Logic and code are often used for source code compilation :./configure && make -j 4 && make install

(3).||

Logic or , If the previous command is successful , Then the following commands will not be executed ; If the previous command is not executed successfully , To execute the later order .

example :

1

2

3

4

5

[[email protected] opt]# ls a || cd /mnt

a

[[email protected] opt]# ls xxx || cd /mnt

ls: cannot access xxx: There is no file or directory

[[email protected] mnt]#

(4). Comprehensive use

Linux The execution order is executed from left to right , From top to bottom .

1

2

3

[[email protected] ~]# cd /root/newDir || mkdir /root/newDir && touch /root/newDir/back.tar && ls /root/newDir

bash: cd: /root/newDir: There is no file or directory

back.tar