Quoting and shell expansion
Prevent the shell from changing your command before the program sees it.
printf '%s\n' ./*.log
25 min read, 30 min lab
foundation
The shell expands globs, variables, command substitutions, and quotes before launching a command. Good operators know whether they want expansion now, later, or not at all.
A filename contains spaces and a cleanup glob might match more files than expected.
Worked command
$ touch "app error.log"$ printf '%s\n' ./*.log$ grep -n "ERROR" "app error.log"$ find . -type f -name '*.log' -print0
Do not loop over `$(ls)` or unquoted file names.
Quote variables and paths unless you intentionally need word splitting.
A file is named `app error.log`. What does `grep -n ERROR app error.log` (unquoted) actually do?
Show the answer
Correct: C. Searches files 'app' and 'error.log' for the pattern ERROR
The shell word-splits on the space before grep runs, so grep sees pattern `ERROR` and two filenames, `app` and `error.log`. Quoting as `"app error.log"` keeps it one argument — without quotes the program never sees the name you intended.
Practice checklist
- Create files with spaces in names.
- Search them with quoted paths.
- Preview glob expansion with `printf` before acting.
Deliverable evidence
- A quoted command that handles a space safely.
- A note explaining what the shell expanded.
shows: A command reads stdin (fd0) and writes two independent outputs — stdout (fd1) and stderr (fd2) — each redirectable on its own, so `>` captures data while `2>` captures diagnostics.
does not prove: It shows the wiring of the three streams, not that any given command actually sends errors to stderr — a few tools misroute diagnostics to stdout, so you still confirm by inspecting both targets.
Commit these to memory, then drill them until recall is automatic.
cue Reference a variable holding a filename that may contain spaces, safely
show recall target
"$file"