bash - Storing into variable a result of boolean expression -
is possible continuously store result of boolean expression variable?
example
ret=0 each in acollection executesomecommand; # vvv compare stored value against returned value , store again ret=$ret || $?; done; [[ ret = 0 ]] && echo "success" the problem if $? 1, $ret still contains zero
ret=0 echo $ret # --> 0 ret=$ret || 1 echo $ret # --> 0 (should 1)
you have grouping/order of operations problem. when do
ret=$ret || 1 it first doing ret=$ret , taking result of , doing || 1 ignoring result of that. part of assignment you're doing assigning ret again.
what want $ret || 1 part , store result, need parens like
ret=$(($ret || 1))
Comments
Post a Comment