What does if [[ $? -ne 0 ]]; mean in .ksh

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.


if [[ $? -ne 0 ]]; 

Is checking return code of immediately previous this if condition.

  • $? means return code
  • $? -ne 0 means previous command returned an error since 0 is considered success

Tags:

Linux

Unix

Bash

Ksh