Word Splitting
noun
say it: “WURD SPLIT-ing” /ˈwɜrd ˈsplɪtɪŋ/
The shell's habit of breaking an unquoted value into separate words wherever it has spaces.
What is word splitting?
Word splitting is the shell cutting the value of an unquoted variable, such as $card, into separate words wherever it has a space. A file called Aunt Rosa.txt then arrives as two names, Aunt and Rosa.txt. Double quotes, "$card", keep the value in one piece.
card='Aunt Rosa.txt'
cat $card # looks for two files: Aunt and Rosa.txt
cat "$card" # prints Aunt Rosa's note
In a sentence
- “Double quotes around "$card" stop word splitting, so the name arrives in one piece.”
- “Because of word splitting, cat $card looked for a file called Aunt.”
Level: Journeyman · More Unix terms at this level
Updated