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

£可爱£侵袭症+ 提交于 2019-12-13 10:05:38

问题


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

~$ echo one && echo two

And

~$ echo one ; echo two

回答1:


~$ 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.



来源:https://stackoverflow.com/questions/24367561/what-is-the-difference-between-and-in-bash-or-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!