010-160 practice question 14 of 15
Which of the following commands output the content of the file Texts 2.txt? (Choose two.)
Full set: 81 questionsThe shell uses spaces to separate arguments on the command line. To pass a filename containing a space, such as "Texts 2.txt", as a single argument to the cat command, the space must be handled specially. This can be done in two primary ways: quoting or escaping. Enclosing the entire filename in single quotes ('Texts 2.txt') causes the shell to treat the enclosed string as a single literal argument. Alternatively, escaping the space with a backslash (Texts\ 2.txt) tells the shell to treat the space as a literal character rather than an argument delimiter. Both methods correctly pass the full filename to cat.
B. cat -- Texts 2.txt passes "Texts" and "2.txt" as two separate arguments to cat, as the space is not escaped or quoted.
C. cat |Texts 2.txt| is invalid syntax. The pipe character (|) is used to redirect the output of one command to the input of another.
D. cat 'Texts\ 2.txt’ fails because a backslash within single quotes is treated as a literal character, not an escape character.
1. GNU Bash Reference Manual (Version 5.2), Section 3.1.2.2 Single Quotes: "Enclosing characters in single quotes (') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash."
2. GNU Bash Reference Manual (Version 5.2), Section 3.1.2.1 Escape Character: "A non-quoted backslash (\) is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of ."
3. MIT OpenCourseWare, 6.S094: The Missing Semester of Your CS Education (Fall 2020), Lecture 1: The Shell: In the "Shell Scripting" section, the lecture explains: "To deal with arguments that contain spaces, you should quote them... Another way of dealing with spaces in arguments is to escape them with a \."
4. GNU Coreutils Manual (Version 9.4), Section 2.1 Common options: "The -- option signifies the end of options. Any arguments following it are treated as file names, even if they begin with a ‘-’." (This confirms -- does not affect space interpretation by the shell itself).
Keep practicing
Take the free 010-160 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 010-160 practice questions
- Question 1What can be found in the /proc/ directory?
- Question 2Which permissions are set on a regular file once the permissions have been modified with …
- Question 3Which of the following commands puts the lines of the file data.csv into alphabetical ord…
- Question 4Which of the following programs are web servers? (Choose two.)
- Question 5The file script.sh in the current directory contains the following content: #!/bin/bash e…
- Question 6Reverse DNS assigns hostnames to IP addresses. How is the name of the IP address 198.51.1…
