Skip to content
Latchkey

What Is Quoting in the Shell? Controlling Expansion

Quoting in the shell tells it to treat text literally, controlling whether spaces split arguments and whether variables and wildcards are expanded.

Quoting is one of the most error-prone parts of shell scripting, and one of the most important. Whether you wrap a value in single quotes, double quotes, or none at all decides whether the shell splits it on spaces, expands its variables, or globs its wildcards. Most "it works until a path has a space" bugs in CI come down to missing quotes.

Why quoting exists

The shell normally splits input on whitespace and expands variables and wildcards. Quoting suspends some or all of that, letting you pass text exactly as written, spaces and special characters included.

Single versus double quotes

  • Single quotes are fully literal: nothing inside is expanded.
  • Double quotes allow variable and command substitution but prevent word splitting and globbing.
  • No quotes means full splitting, expansion, and globbing.

The classic bug

Unquoted, rm $FILE breaks if $FILE contains a space, because the shell splits it into two arguments. Writing rm "$FILE" keeps it as one, which is why variables should almost always be double-quoted.

Quoting and expansion together

Double quotes are the sweet spot in most scripts: you still get variable values via $VAR, but spaces in those values stay intact and wildcards are not accidentally expanded.

Quoting in CI

CI paths and inputs often contain spaces or special characters you did not anticipate. Double-quoting every variable expansion, like "${INPUT}", is the single most effective habit for avoiding mysterious word-splitting failures in pipelines.

Robust scripts on managed runners

On Latchkey runners, the same quoting rules apply as on any Linux shell. Combining set -u with consistent double-quoting catches both unset and misquoted variables before they corrupt a build.

Key takeaways

  • Quoting controls word splitting and variable and wildcard expansion.
  • Single quotes are literal; double quotes expand variables but keep spaces intact.
  • Double-quoting every variable, like "$VAR", prevents most CI script bugs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →