What is the difference between double-ampersand (&&) and semicolon (;) in Linux Bash?

前端 未结 3 1826
盖世英雄少女心
盖世英雄少女心 2020-12-07 10:03

What is the difference between ampersand and semicolon in Linux Bash?

For example,

$ command1 && command2

vs



        
3条回答
  •  爱一瞬间的悲伤
    2020-12-07 11:06

    command1 && command2

    command1 && command2 executes command2 if (and only if) command1 execution ends up successfully. In Unix jargon, that means exit code / return code equal to zero.

    command1; command2

    command1; command2 executes command2 after executing command1, sequentially. It does not matter whether the commands were successful or not.

提交回复
热议问题