What is the difference between && and ; in bash or

2019-10-10 04:32发布

What is the difference between && and ; in bash or command? Eg:

~$ echo one && echo two

And

~$ echo one ; echo two

标签: linux bash gnu
1条回答
够拽才男人
2楼-- · 2019-10-10 05:24
~$ echo one && echo two

This runs the 2. command only if the first command succeeds.

~$ echo one ; echo two

This always runs the 2. command.

~$ echo one || echo two

This runs the 2. command only if the first command fails.

A command is considered successful if its exit code is 0, and considered failed if its exit code is != 0.

查看更多
登录 后发表回答