I have a following piece of code that says if everything is executed mail a person if it fails mail the person with a error message.
if [[ $? -ne 0 ]]; then
mailx -s" could not PreProcess files" [email protected]
else
mailx -s" PreProcessed files" [email protected]
fi
done
I am new to linux coding I want to understand what if [[ $? -ne 0 ]];
means
Breaking it down, simple terms:
[[ and ]]
... signifies a test is being made for truthiness.
$?
... is a variable holding the exit code of the last run command.
-ne 0
... checks that the thing on the left ($?
) is "not equal" to "zero". In UNIX, a command that exits with zero succeeded, while an exit with any other value (1, 2, 3... up to 255) is a failure.