LPI
010-160 · Question #84
010-160 Question #84: Real Exam Question with Answer & Explanation
The correct answer is A: 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.
The Power of the Command Line
Question
Which of the following commands output the content of the file Texts 2.txt? (Choose two.)
Options
- Acat 'Texts 2.txt'
- Bcat -- Texts 2.txt
- Ccat [Texts 2.txt]
- Dcat 'Texts| 2.txt'
- Ecat Texts\ 2.txt
Explanation
When a filename contains spaces, the shell requires quoting or escaping so it is treated as a single argument rather than multiple arguments.
Common mistakes.
- B. The double-dash
--signals the end of options but does not quote or join arguments, socatreceives two separate arguments - 'Texts' and '2.txt' - and will report errors for both. - C. 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. - D. 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'.
Concept tested. Shell quoting and escaping spaces in filenames
Reference. https://www.gnu.org/software/bash/manual/bash.html#Quoting
Topics
#cat command#filename quoting#escape characters#special characters
Community Discussion
No community discussion yet for this question.