What does if [[ $? -ne 0 ]]; mean in .ksh
bash, ksh, linux, unix
Solution
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.
Problem
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" xyz@abcd.com else mailx -s" PreProcessed files" xyz@abcd.com fi done ``` I am new to linux coding I want to understand what `if [[ $? -ne 0 ]];` means