- 01Setting up (what you'll need)
- 02Your first shell script (echo)
- 03Using variables
- 04Command-line arguments ($1, $2 ...)
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Repeating (the while loop)
- 08Writing your own function
- 09Working with arrays
- 10Command substitution ($())
- 11Working with strings (parameter expansion)
- 12Reading from standard input (read)
- 13Exit status and && / ||
- 14Pipes and redirection
- 15The case statement
- 16Arithmetic ($(( )))
- 17The basics of grep, sed and awk
- 18Argument checks and error handling
- 19Function return values and exit codes
- 20[Project] Build a small log-tallying script
Exit status and && / ||
This lesson covers the exit status that reports whether a command succeeded, and the && and || operators built on it.
Every command returns a number — its exit status — when it finishes. Zero means success and anything else means failure. && runs the next command only if the previous one succeeded; || runs it only if the previous one failed.
The sample code writes mkdir backup && echo "Created successfully", displaying the message only when the folder was created.
A common early stumble is confusing && and || with the logical operators of other languages. What is distinctive here is that the branch is on whether a command succeeded, not on whether a value is true.
In professional work, they are used to build safe sequences: continue only if the backup succeeded, print an error and stop if a command failed.
๐งช This site can't compile or run Shell Script directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
