linux - Linux Bash 中的双与号 (&&) 和分号 (;) 有什么区别?

Linux 中的 & 和分号有什么区别 Bash ?

例如,

$ command1 && command2

$ command1; command2

最佳答案

&& 运算符是 bool AND 运算符:如果左侧返回非零退出状态,则运算符返回该状态并且不对右侧求值(它短路),否则它评估右侧并返回其退出状态。这通常用于确保 command2 仅在 command1 成功运行时运行。

; 标记只是分隔命令,因此无论第一个命令是否成功,它都会运行第二个命令。

关于linux - Linux Bash 中的双与号 (&&) 和分号 (;) 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25669540/

相关文章:

linux - 如何计算包括子目录在内的代码行数

python - 如何将 SqlAlchemy 结果序列化为 JSON?

linux - 带有 -i 选项的 sed 命令(就地编辑)在 Ubuntu 上运行良好,但在 Ma

linux - 什么 linux shell 命令返回字符串的一部分?

linux - 如何获取 Linux/UNIX 上当前的网络接口(interface)吞吐量统计信息

linux - cd进入目录没有权限

python - 导入错误 : No module named PIL

python - pip 安装 : Please check the permissions and

python - 在python中跳过for循环的第一个条目?

python - glob.glob() 的返回值是如何排序的?