Bash/sh - difference between && and ;

前端 未结 7 831
轮回少年
轮回少年 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条回答
  •  -上瘾入骨i
    2020-12-07 11:57

    In cmd1 && cmd2, cmd2 is only executed if cmd1 succeeds (returns 0).

    In cmd1 ; cmd2, cmd2 is executed in any case.

    Both constructs are part of a POSIX-compliant shell.

提交回复
热议问题