Compound commands overview | |
---|---|
Grouping | |
{ …; } |
command grouping |
( … ) |
command grouping in a subshell |
Conditionals | |
[[ ... ]] |
conditional expression |
if …; then …; fi |
conditional branching |
case … esac |
pattern-based branching |
Loops | |
for word in …; do …; done |
classic for-loop |
for ((x=1; x<=10; x++)); do ...; done |
C-style for-loop |
while …; do …; done |
while loop |
until …; do …; done |
until loop |
Misc | |
(( ... )) |
arithmetic evaluation |
select word in …; do …; done |
user selections |
Introduction to expansions and substitutions | |
---|---|
{A,B,C} {A..C} |
Brace expansion |
~/ ~root/ |
Tilde expansion |
$FOO ${BAR%.mp3} |
Parameter expansion |
`command` $(command) |
Command substitution |
<(command) >(command) |
Process substitution |
$((1 + 2 + 3)) $[4 + 5 + 6] |
Arithmetic expansion |
Hello <---> Word! |
Word splitting |
/data/*-av/*.mp? |
Pathname expansion |
Declaration commands Commands that set and query attributes/types, and manipulate simple datastructures. |
Alt | Type | |
---|---|---|---|
declare | Display or set shell variables or functions along with attributes. | typeset |
builtin |
export | Display or set shell variables, also giving them the export attribute. | - | special builtin |
eval | A common misspelling of "evil" | - | special builtin |
local | Declare variables as having function local scope. | - | builtin |
readonly | Mark variables or functions as read-only. | declare -r |
special builtin |
unset | Unset variables and functions. | - | special builtin |
shift | Shift positional parameters | - | special builtin |
Control flow and data processing Commands that operate on data and/or affect control flow. |
Alt | Type | |
---|---|---|---|
colon | "true" null command | true | special builtin |
dot | Source external files | source | special builtin |
false | Fail at doing nothing | - | builtin |
continue / break | continue with or break out of loops. | - | special builtin |
let | Arithmetic evaluation - an old fashioned way. | - | builtin |
return | Break out of a function, returning the specified exit status. | - | special builtin |
[ | The classic test command. |
test | builtin |
Process and Job control Commands related to jobs, signals, process groups, subshells. |
Alt | Type | |
exec | Replace the shell, set redirections. | - | special builtin |
exit | Exit the shell. | - | special builtin |
trap | Set traps. | - | special builtin |
times | Display process times. | - | special builtin |
wait | Wait for background jobs and asynchronous lists. | - | builtin |
I/O Commands for reading/parsing input, or producing/formatting output of standard streams. |
Alt | Type | |
---|---|---|---|
coproc | Co-processes: Run a compound command in the background with async I/O. | - | keyword |
echo | Create output from args. | - | builtin |
mapfile | Create arrays from lines of input | readarray |
builtin |
printf | "advanced echo ." |
- | builtin |
read | Build variables or arrays from input streams. | - | builtin |
Configuration and Debugging Commands that modify shell behavior, change special options, assist in debugging. |
Alt | Type | |
caller | Identify/print execution frames. | - | builtin |
set | Control positional parameters and shell behaviour. | - | special builtin |
shopt | set/get shell options. | - | builtin |