Lesson 3.4: Spaces in paths and file names
Why a space splits a name into two arguments, and the three ways to keep it together: double quotes, single quotes and the backslash; how ls and Tab completion show such names.
13 min
You will learn to
- Explain why mkdir My Files makes two directories
- Quote names with " " and ' ' and escape single characters with \
- Know the difference between single and double quotes for $
- Prefer names without spaces for files you create
Key terms
- Word splitting
- The shell cuts a command line into separate arguments at every space (and tab).
- Double quotes " "
- Keep everything inside as one argument; $variables and $(commands) inside are still expanded.
- Single quotes ' '
- Keep everything inside as one argument, exactly as written: nothing is expanded, not even $.
- Escaping with \
- A backslash makes the next character ordinary, so a space after it doesn't split.
- Special characters
- Characters the shell treats specially and that need quoting in names: space, ' " $ * ? [ ] ( ) & ; | < > # ~ and the backslash.
← Working with files and directories · All lessons · Wildcards and path expansion →