我在 bash 中尝试了以下命令
echo this || echo that && echo other
这给出了输出
this
other
我不明白!
我的试运行是这样的:
-
echo this || echo that && echo other
暗示true || true && true
- Since,
&&
has more precedence
than ||
,第二个表达式首先计算
- Since,
both are true
, the ||
被评估也给出 true。
- 因此,我得出的结论是:
that
other
this
来自 Java 背景&&
优先于||
,我无法将其与 bash 联系起来。
任何输入都会非常有帮助!
From man bash http://www.gnu.org/software/bash/manual/bashref.html#Lists
3.2.3 命令列表
列表是由运算符 ';'、'&'、'&&' 或 '||' 之一分隔的一个或多个管道的序列,并且可以选择以 ';'、'&' 或新队。
在这些列表运算符中,‘&&’和‘||’具有相同的优先级,后跟“;”和“&”,它们具有相同的优先级。
所以,你的例子
echo this || echo that && echo other
可以读成
(this || that) && other
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)