Last Updated: February 25, 2016
· jmarizgit

Check if your shell command was successfully executed

Every executed command in UNIX systems have an exit status code on it. That means that we can actually identify if a command was successfully completed of generate some kind of error.

After execute a command on your terminal window type the following:

$ echo $?

If your previous code was successfully executed this command should show "0" which indicates that your command was successfully executed.

Happy hacking!

1 Response
Add your response

With ZSH (and maybe with Bash) you can have $? printed right in your PS prompt. That way you can't accidentally lose the data if you forget to echo.

over 1 year ago ·