Variables store values. Assign with VAR=value (no spaces around =). Access with $VAR or ${VAR}. Variables are case-sensitive and untyped—everything is a string unless used in arithmetic.
$ NAME="Alice" $ echo $NAME # prints: Alice $ echo ${NAME}_suffix # prints: Alice_suffix $ X=5; Y=$((X + 3)); echo $Y # arithmetic: prints 8
Unset variables are empty strings. Quote variable references to preserve spaces: "$VAR" vs $VAR.
Quoting controls how the shell interprets special characters. Double quotes "..." preserve most meaning but allow expansion of $VAR and backticks. Single quotes '...' prevent all expansion. Backslash \ escapes a single character.
$ echo "Hello $USER" # expands $USER $ echo 'Hello $USER' # literal: Hello $USER $ echo "Cost: \$5" # literal: Cost: $5 $ echo $'Hello\nWorld' # ANSI-C quoting: interprets \n
Use single quotes for literals, double quotes when you need expansion.
Expansion is how the shell transforms text before running commands. Types include:
$VAR, ${VAR}, ${VAR:-default}$((2 + 2))$(command) or `command` {a,b,c} expands to a b c~ becomes $HOME*.txt matches files ending in .txt$ echo {1,2,3} # expands to: 1 2 3 $ echo /home/*/Desktop # expands to matching directories $ echo "Today is $(date +%Y)" # command substitution
Expansions happen after quoting, so "$VAR" expands but '$VAR' does not.