When a program ends, it indicates its status with an exit code. The exit code is a small integer; by convention, an exit code of zero denotes successful execution,
while nonzero exit codes indicate that an error occurred.
Some programs use different nonzero exit code values to distinguish specific errors.
With most shells, it's possible to obtain the exit code of the most recently executed program using the special $? variable.
$ ls /
$ echo $?
0
$ ls bogusfile
ls: bogusfile: No such file or directory
$ echo $?
1