I'm looking to be able to always execute both validateA and validateB:
function validateA() {
echo "A [ok]"
return 0
}
function validateB() {
echo "B [ok]"
return 0
}
if ! validateA | ! validateB; then
echo "validation [fail]"
exit 1
else
echo "validation [ok]"
exit 0
fi
You can just call them regardless and capture the return values:
function validateA() {
echo "A [fail]"
return 1
}
function validateB() {
echo "B [ok]"
return 0
}
validateA ; vA=$?
validateB ; vB=$?
if [[ $vA -ne 0 || $vB -ne 0 ]] ; then
echo "validation [fail]"
exit 1
else
echo "validation [ok]"
exit 0
fi
This outputs:
A [fail]
B [ok]
validation [fail]
I had the same question and ended up doing something like this:
rc=0
if ! validateA ; then rc=1; fi
if ! validateB ; then rc=1; fi
return $rc
It's the same principle as other answers but a more condensed syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With