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

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

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

For example,

$ command1 && command2

vs



        
3条回答
  •  萌比男神i
    2020-12-07 11:07

    The former is a simple logic AND using short circuit evaluation, the latter simply delimits two commands.

    What happens in real is that when the first program returns a nonzero exit code, the whole AND is evaluated to FALSE and the second command won't be executed. The later simply executes them both in order.

提交回复
热议问题