在Linux Bash中,双与号(&&)和分号(;)之间有什么区别? [英] What is the difference between double-ampersand (&&) and semicolon (;) in Linux Bash?
问题描述
Linux Bash 中的&符和分号有什么区别? >
例如,
$ command1 && command2
vs
$ command1; command2
&&
运算符是布尔AND运算符:如果左侧返回非零退出状态,则该运算符将返回该状态并且不评估右侧(短路),否则评估右侧并返回其退出状态.这通常用于确保command2
仅在command1
成功运行时才运行.
;
令牌只是分隔命令,因此无论第一个命令是否成功,它都会运行第二个命令.
What is the difference between ampersand and semicolon in Linux Bash?
For example,
$ command1 && command2
vs
$ command1; command2
The &&
operator is a boolean AND operator: if the left side returns a non-zero exit status, the operator returns that status and does not evaluate the right side (it short-circuits), otherwise it evaluates the right side and returns its exit status. This is commonly used to make sure that command2
is only run if command1
ran successfully.
The ;
token just separates commands, so it will run the second command regardless of whether or not the first one succeeds.
这篇关于在Linux Bash中,双与号(&&)和分号(;)之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!