Day 38 - Exit code

10 May 2017

In a shell, you can get the exit code of the last command executed, using the variable $? (or ${?}).

Examples:

$ bash -c 'exit 42'
$ echo $?
42

$ ls /foobar
ls: /foobar: No such file or directory
$ echo $?
1

$ pwd
/Users/samuelberthe/project/github.com/devops-tip-of-the-day/_posts
$ echo $?
0