Bash/sh - difference between && and ;

前端 未结 7 809
轮回少年
轮回少年 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:06

    && allows for conditional execution while ; always has the second command being executed.

    In e.g. command1 && command2, command2 will only execute when command1 has terminated with exit 0, signalling all went well, while in command1 ; command2 the second command will always be executed no matter what the result was of command1.

提交回复
热议问题