Bash/sh - difference between && and ;

前端 未结 7 849
轮回少年
轮回少年 2020-12-07 11:22

I normally use ; to combine more than one command in a line, but some people prefer &&. Is there any difference? For example, cd ~; c

7条回答
  •  天涯浪人
    2020-12-07 12:08

    I'm using && because a long time ago at the nearby computer:

    root# pwd
    /
    root# cd /tnp/test; rm -rf *
    cd: /tnp/test: No such file or directory
    ...
    ... and after a while ...
    ...   
    ^C
    

    but not helped... ;)

    cd /tnp/test && rm -rf * is safe... ;)

提交回复
热议问题