Bash syntax and operations

Compound commands

Compound commands overview
{ …; } command grouping
( … ) command grouping in a subshell
[[ ... ]] conditional expression
if …; then …; fi conditional branching
case … esac pattern-based branching
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
(( ... )) arithmetic evaluation
select word in …; do …; done user selections

Expansions and substitutions

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

Builtin Commands

This is a selection of builtin commands and command-like keywords, loosely arranged by their common uses. These are provided directly by the shell, rather than invoked as standalone external commands.

Declaration commands
Commands that set and query attributes/types, and manipulate simple datastructures.
Alt Type
declareDisplay or set shell variables or functions along with attributes. typeset builtin
exportDisplay or set shell variables, also giving them the export attribute. - special builtin
evalA common misspelling of "evil" - special builtin
localDeclare variables as having function local scope. - builtin
readonlyMark variables or functions as read-only. declare -r special builtin
unsetUnset variables and functions. - special builtin
shiftShift positional parameters - special builtin
Commands for reading/parsing input, or producing/formatting output of standard streams.
Alt Type
coprocCo-processes: Run a compound command in the background with async I/O. - keyword
echoCreate output from args. - builtin
mapfileCreate arrays from lines of input readarray builtin
printf"advanced echo." - builtin
readBuild variables or arrays from input streams. - builtin
Configuration and Debugging
Commands that modify shell behavior, change special options, assist in debugging.
Alt Type
callerIdentify/print execution frames. - builtin
setControl positional parameters and shell behaviour. - special builtin
shoptset/get shell options. - 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
dotSource external files source special builtin
falseFail at doing nothing - builtin
continue / breakcontinue with or break out of loops. - special builtin
letArithmetic evaluation - an old fashioned way. - builtin
returnBreak 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
execReplace the shell, set redirections. - special builtin
exitExit the shell. - special builtin
trapSet traps. - special builtin
timesDisplay process times. - special builtin
waitWait for background jobs and asynchronous lists. - builtin
History, programmable completion, directory stack.
Alt Type