Inside a bash [[…]] (and inside the older […] in most shells) what matters is if the value tested has some characters or not:
$ [[ somevalue ]] && echo "yes" || echo "no"
If the value tested if empty, the test fails:
$ [[ "" ]] && echo "yes" || echo "no"
no
That is also true for variables:
$ somevalue="a false string"
$ [[ $somevalue ]] && echo "yes" || echo "no"
yes
$ somevalue=""
$ [[ $somevalue ]] && echo "yes" || echo "no"
no
So, [[…]] is limited to testing strings not "exit codes".
Your functions define "exit codes" not strings.
You may
define the values of mytrue and myfalse to be variables that represent those values:
mytrue=A_True_Value
myfalse=""
And use them:
$ show="dont-show"
$ [[ ${SHOW} == "show" || $mytrue ]] && echo "ok" || echo "wrong"
ok
$ [[ ${SHOW} == "show" || $myfalse ]] && echo "ok" || echo "wrong"
wrong
Or, actually test exit codes outside a [[…]] idiom:
$ mytrue(){ return 0; }
$ if mytrue; then echo "ok"; else echo "wrong"; fi
ok
$ mytrue && echo "ok" || echo "wrong"
ok
One (more complex) alternative is to make the functions emit a value and call the execution of the code in the functions from the [[…]] idiom:
$ mytrue(){ echo "A_True_Value"; }
$ myfalse(){ echo ""; }
$ show="dont-show"
$ [[ ${SHOW} == "show" || $(mytrue) ]] && echo "ok" || echo "wrong"
ok
KISS
But (probably) the simplest of solutions is the best solution:
myfalse=""
mytrue="true"
test-conditional () {
show="dont-show"
[[ ${show} == "show" || $mytrue ]] && echo "ok" || echo "wrong"
[[ ${show} == "show" && $mytrue ]] && echo "err" || echo "ok"
[[ ${show} == "show" || $myfalse ]] && echo "err" || echo "ok"
[[ ${show} == "show" && $myfalse ]] && echo "err" || echo "ok"
show="show"
[[ ${show} == "show" || $mytrue ]] && echo "ok" || echo "err"
[[ ${show} == "show" && $mytrue ]] && echo "ok" || echo "err"
[[ ${show} == "show" || $myfalse ]] && echo "ok" || echo "err"
[[ ${show} == "show" && $myfalse ]] && echo "err" || echo "ok"
}
test-conditional
==comparison inside, i.e[[ ${SHOW} == "show" ]] || mytrue