Exit Codes

In this lesson, you will find out what an exit code is, how you can set one in a script and a function, some conventions around exit codes, and other 'special' parameters in bash.

How Important is this Lesson?

Most bash scripts won’t be completely comprehensible or safely written unless exit codes are understood.

What Is An Exit Code?

After you run a command, function or builtin, a special variable is set that tells you what the result of that command was. If you’re familiar with HTTP codes like 200 or 404, this is a similar concept to that.

To take a simple example, type this in:

Get hands-on with 1200+ tech skills courses.