word splitting
The step where bash cuts the result of an unquoted expansion into separate words at spaces, tabs and newlines.
An unquoted variable holding a file name with spaces can make commands such as rm act on the wrong files.
In more detail
It is why rm $f, with f set to my notes.txt, tries to delete two files named my and notes.txt. The characters it cuts at come from IFS. Double quotes around the expansion switch it off, which is why nearly every expansion should be quoted.
Related terms
- IFS — The internal field separator: a shell variable listing the characters that word splitting and read cut text at.
- double quotes — Quotes that keep text together as one word but still let dollar expansions and backticks work inside.
- globbing — The step where bash replaces a word containing a star, a question mark or square brackets with the sorted list of file names that match it.
- SC2086 — The ShellCheck warning for an unquoted variable expansion, which may be split into several words or expanded as a glob.
Taught in
- Making, Copying, Moving And Removing — Bash Scripting & Command Line Automation
- What Bash Does To A Line Before It Runs It — Bash Scripting & Command Line Automation
- Single Quotes, Double Quotes, Backslash — Bash Scripting & Command Line Automation
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- The Field Separator, And Reading Lines Safely — Bash Scripting & Command Line Automation
- Arrays, And Why Dollar At Is Not Dollar Star — Bash Scripting & Command Line Automation
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation
- ShellCheck — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation
- POSIX sh Versus Bash — Bash Scripting & Command Line Automation
- find And xargs — Bash Scripting & Command Line Automation