0

I encountered $? in one of the shell scripts I work on integrating (not written by me).

Just wanted to confirm that it means the return code of the previous command.

The usage is something like

runSomeCommand $VAR1 $VAR2 $VAR3

processResult $?
amphibient
  • 27,548
  • 48
  • 136
  • 231
  • 1
    possible duplicate of [what does '$?' mean in a shell script?](http://stackoverflow.com/questions/12741710/what-does-mean-in-a-shell-script) – devnull May 22 '14 at 01:36
  • You can see the [link](http://www.tutorialspoint.com/unix/unix-special-variables.htm) Or my answers is in http://stackoverflow.com/a/26866587/1920536 – biolinh Nov 11 '14 at 14:00

1 Answers1

5

$? is the exit status of the last executed command.

ls
....
echo $?
0

$ ls notexistingfile
ls: cannot access notexistingfile: No such file or directory

echo $?
2
Karoly Horvath
  • 91,854
  • 11
  • 113
  • 173