

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Help
incomplete
2: Flags
incomplete
3: Positional Arguments
incomplete
4: Exit Codes
incomplete
5: Standard Output
incomplete
6: Standard Error
incomplete
7: Standard In
incomplete
8: Piping
incomplete
9: Unix Philosophy
incomplete
This lesson's interactive features are locked, please to keep using them
Exit codes (sometimes called "return codes" or "status codes") are how programs communicate back whether they ran successfully or not.
0 is the exit code for success. Any other exit code is an error. 9 times out of 10, if a non-zero exit code is returned (meaning an error) it will be 1, which is the "catch-all" error code.
Programs that call other programs use error codes to figure out if execution was successful. For example, if the Boot.dev server program exits with a non-zero exit code, we have another program that will automatically restart it and log the error.
In a shell, you can access the exit code of the last program you ran with the question mark variable ($?):
cat greeting.txt
# General Kenobi!
echo $?
# 0
cat file/that/does/not/exist.txt
echo $?
# 1
You can run multiple commands on a single line by separating them with a semicolon (;):
command1 ; command2
If you only want the second command to run when the first command succeeds (exit code 0), use &&:
command1 && command2
Submit the shell checks.