Is there an elegant way to compare exit codes of two functions in bash? For example
b ()
{
local r=$(rand -M 2 -s $(( $(date +%s) + $1 )) );
echo "b$1=$r";
return $r;
} # just random boolean
b1 () { b 1; return $?; } # some boolean function
b2 () { b 2; return $?; } # another boolean function ( another seed )
I'd like to use something like this
if b1 == b2 ; then echo 'then'; else echo 'else'; fi
but stuck with this "not xor" implementation
if ! b1 && ! b2 || ( b1 && b2 ) ; then echo 'then'; else echo 'else'; fi
And speaking more generally, can one compare exit codes of two functions arithmetically and use that comparison in if statement?
b 1; return $?;to do? Since the result of runningb 1is not saved in a variable, what are you hoping to accomplish by running it? Separately, what do you expect the value of$?to signify?0means success, any other non-zero value means failure.