Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Shell Expansion

Direct answer

Shell expansion is how Bash rewrites a command before running it: variables, globs like *.log, brace expansion {a,b}, tilde and arithmetic $(( )). Quoting controls which expansions happen.

When to use this

Use this when Bash rewrites commands before running them.

First 30 seconds

1. Expansion order: brace, tilde, parameter, command, arithmetic, word splitting, globbing.

2. Quotes prevent splitting/globbing.

3. nullglob/failglob for globs.

4. Parameter expansion for string ops.

5. Be explicit.

Operational verification

text → expansions → final words

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
GNU Bash shell automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformGNU Bash shell automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when Bash rewrites commands before running them.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Common mistakes Narrow the fault
  • Unquoted $var breaking on spaces.
  • A glob with no matches staying literal (use shopt -s nullglob).
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Bash expands variables, globs, braces, tilde and arithmetic before running.
  • Double quotes stop word splitting and globbing.
  • Unmatched globs stay literal unless nullglob is set.
Key checks
  • echo {1..3} — brace expansion
  • shopt -s nullglob — empty glob handling
  • echo "${var//old/new}" — parameter expansion
ReferenceWhy it matters1 section · depth on demand

What it is

Bash expands words before running a command: variables ($x), globs (*.cfg), braces ({a,b}), tilde (~) and arithmetic ($((1+2))). Quote variables to stop word splitting and glob expansion.

ReferenceImportant terms & boundaries2 sections · depth on demand

How it works

Bash expands a command line in a fixed order: brace expansion, tilde, parameter/variable, arithmetic, command substitution, word splitting, then pathname (glob) expansion, and finally quote removal. Double quotes stop word splitting and globbing but still allow $var and $(...); single quotes stop everything.

Example

for f in backups/*.cfg; do echo "$f"; done
mkdir -p site/{oslo,bergen}
echo $((count + 1))
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docGNU Bash shell automation current

Authoritative/upstream documentation reviewed for bounded claims in Bash Automation > Shell Expansion. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%
Confirmation

Confirm action

Continue?