amphibient
amphibient

Reputation: 31258

What does $? mean in shell scripting?

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 $?

Upvotes: 1

Views: 4025

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96266

$? 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

Upvotes: 6

Related Questions