【发布时间】:2018-09-17 07:12:35
【问题描述】:
为什么在使用test 和不使用test 评估相同的表达式时,以下脚本会给出不同的输出?要考虑哪些规则:运算符优先级、从左到右或从右到左的参数评估......?在我看来,在这个基础层面理解 bash 的逻辑很重要。
function a()
{
local r=1
printf "a%d" $r
return $r
}
function b()
{
local r=1
printf "b%d" $r
return $r
}
function c()
{
local r=1
printf "c%d" $r
return $r
}
printf "$BASH_VERSION\n" #outputs 4.3.48(1)-release
a || b && c #outputs a1b1
printf "\n"
test a || b && c #outputs c1
printf "\n"
【问题讨论】:
标签: bash