【发布时间】:2021-07-04 12:41:35
【问题描述】:
我在 bash 上尝试了以下命令
echo this || echo that && echo other
这给出了输出
this
other
我不明白!
我的试跑是这样进行的:
-
echo this || echo that && echo other暗示true || true && true - 由于
&&比more precedence具有||,因此第二个表达式首先计算 - 由于
both are true,||的评估结果也为真。 - 因此,我得出的结论是:
那个
其他
这个
来自&& 的优先级高于|| 的 Java 背景,我无法将其与 bash 联系起来。
任何输入都会非常有帮助!
【问题讨论】:
-
注意从左到右关联的优先级相同