Bash/sh - difference between && and ;

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

    && means to execute next command if the previous exited with status 0. For the opposite, use || i.e. to be executed if previous command exits with a status not equal to 0 ; executes always.

    Very useful when you need to take a particular action depending on if the previous command finished OK or not.

提交回复
热议问题