I'm having a weird situation where when I run a conditional check against a function return inside a print statement, the global variable that is set in the function does not want to work. Let me give the example:
function VALIDATE()
{
BLAH BLAH BLAH
ERROR="IT FAILED"
return 0
}
######## Start relevant code ########
printf "%-50s %10s\n" " Validating and sanitizing input..." "$(if VALIDATE $HOST; then echo "[$RED FAIL $RESET]"; else echo "[$GREEN OK $RESET]"; fi)"
if [ -z $ERROR ]; then
echo $ERROR
else
echo "YAHOO IT WORKS"
fi
Something about running the function check inside the printf statement prevent $ERROR from being passed successfully. If for example I remove the formatting created by printf and rerun the code, ERROR works as expected.
Running the function inside the printf was initially necessary to facilitate the question answer type formatting of the output. Yes it is possible to rewrite this such that the fnction is called outside the printf statement, but this will require extra code, and I wanted to see if it could be made to work first using this short hand method. Any suggestions? Thank you!
Validating and sanitizing input..is printed after theVALIDATEfunction is run....