Learn › Linux Foundations
Chaining
Chain commands together with semicolons, AND/OR operators, subshells, brace groups, and exit codes. Master the special variables that track process results.
Labs in this module
- The semicolon: run commands in sequence - Put several commands on one line with the semicolon and the shell runs them left to right, no matter how each one turns out. You chain echoe
- Chaining Commands with || - The or-operator runs its right side only when the left side fails. Fire fallbacks with false echo recovered, rescue a failing ls, prove succ
- The $? Exit Code - Read the invisible scoreboard every command leaves behind. Make commands succeed and fail on purpose, read the last exit code with echo $?,
- The $! Background PID - Meet $!, the shell variable that remembers the PID of your most recent background job. Fall into the famous ask-too-early trap on purpose, h
- Exit Codes - Every command reports a hidden number when it finishes: 0 for success, non-zero for failure. Make it visible with true, false, and a real ls
- The $ Shell PID Variable - Meet $, the variable that holds your shell's own process ID. Learn what a PID is, prove $ is a live number that varies per session but nev
- {} Brace Grouping - Bundle commands into one unit with a brace group { }. See why braces run in your current shell so a variable or a cd sticks, contrast it wit
- Chaining Commands with && - Every command leaves an exit code, and && reads it. Learn the success gate by doing: read exit codes with $?, watch the blind semicolon run
- () Subshell Grouping - Group commands in a subshell with ( ): a temporary copy of your shell where a variable or a cd vanishes when the group ends. Prove the isola