010-160 · Question #84
Which of the following commands output the content of the file Texts 2.txt? (Choose two.)
The correct answer is A. cat 'Texts 2.txt' E. cat Texts\ 2.txt. When a filename contains spaces, the shell requires quoting or escaping so it is treated as a single argument rather than multiple arguments.
Question
Options
- Acat 'Texts 2.txt'
- Bcat -- Texts 2.txt
- Ccat [Texts 2.txt]
- Dcat 'Texts| 2.txt'
- Ecat Texts\ 2.txt
How the community answered
(23 responses)- A91% (21)
- B4% (1)
- C4% (1)
Why each option
When a filename contains spaces, the shell requires quoting or escaping so it is treated as a single argument rather than multiple arguments.
Enclosing the filename in single quotes (`'Texts 2.txt'`) passes the entire string including the space as one argument to `cat`, correctly identifying the file.
The double-dash `--` signals the end of options but does not quote or join arguments, so `cat` receives two separate arguments - 'Texts' and '2.txt' - and will report errors for both.
Square brackets in the shell are glob/pattern matching metacharacters, not a quoting mechanism, so `[Texts 2.txt]` would be interpreted as a character class pattern, not the literal filename.
Single-quoting preserves every character literally, so `'Texts| 2.txt'` would look for a file whose name contains a pipe character, which does not match the actual filename 'Texts 2.txt'.
A backslash before the space (`Texts\ 2.txt`) is a shell escape sequence that tells the shell to treat the space as a literal character rather than an argument separator, so `cat` receives the correct single filename.
Concept tested: Shell quoting and escaping spaces in filenames
Source: https://www.gnu.org/software/bash/manual/bash.html#Quoting
Topics
Community Discussion
No community discussion yet for this question.