0

I have script here and I should convert it to python. But one thing that I dont know.

What does this line means:

 if [ $? != 0 ]
            then
                    echo "$i NOT FOUND!"
                    retval=255
            fi

Need help. Thank you.

akimebless
  • 33
  • 1
  • 3
  • 8

3 Answers3

1

That is testing the exit status (or return code) of the previous command. A value of non-zero traditionally means error.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

This question is answered here: What is the $? variable in shell scripting?

$? is used to find the error code of the last executed command. Try the following in the shell:

ls somebogusfile
echo $?

You will get the error code thrown by the ls command.

Community
  • 1
  • 1
bogeylicious
  • 5,071
  • 3
  • 25
  • 17
  • If the question is a duplicate of another question that already has an answer, just vote to close it as a dup, don't copy the answer from the other question. – abarnert Nov 25 '14 at 02:01
0

It is the exit value of the last command run in the foreground.

man bash. :)

Beirdo
  • 414
  • 8
  • 15