Skip to content
Linux Basics: Quoting Text and Matching Filenames

Linux Basics: Quoting Text and Matching Filenames

October 8, 2026

Quotes control what Bash treats as one argument. Filename patterns let the shell select several files at once. Knowing the difference helps avoid surprises when names contain spaces.

Use Bash on Debian or Ubuntu. Run the examples in order in the same shell, starting with a new practice directory:

practice=$(mktemp -d) && cd "$practice"

Continue only if that command succeeds. The examples assume Bash’s default filename-matching settings.

Keep a value together

name='weekly notes'
printf '<%s>\n' "$name"
<weekly notes>

Double quotes preserve the spaces while allowing $name to expand. Without those quotes, this value becomes two arguments:

printf '<%s>\n' $name
<weekly>
<notes>

Single quotes keep the dollar sign literal:

printf '%s\n' '$name'
$name

Prefer "$name" when passing a variable’s value to a command.

Expand a filename pattern

touch 'weekly notes.txt' tasks.txt
printf '<%s>\n' ./*.txt
<./tasks.txt>
<./weekly notes.txt>

The shell expands * to matching filenames before printf runs. Each matched filename stays one argument, including a name containing spaces. The displayed order assumes the C locale; sorting can differ in other locales.

Quoting the whole pattern prevents that expansion:

printf '%s\n' './*.txt'
./*.txt

With default Bash settings, * does not match a leading dot, and an unmatched pattern remains literal. Preview a pattern with printf before using it in a command that changes files.

Clean up

Remove only the two practice files, then the empty directory:

rm -- 'weekly notes.txt' tasks.txt
cd / && rmdir -- "$practice"
unset practice name

Reference

Debian Bash manual

Acknowledgements

This post was created with assistance from AI.

Linux Basics — lesson 21 of 25. Series index

Previous: Managing Packages with apt · Next: Replacing Text with sed

Last updated on