Unix Questions and Answers – Pattern Matching, Escaping and Quoting – 2

This set of Unix test focuses on “Pattern Matching, Escaping and Quoting – 2”.

1. Providing a backslash (\) before the wild card to remove its special meaning is called _____
a) escaping
b) quoting
c) listing
d) pattern matching
View Answer

Answer: a
Explanation: We know that shell uses some special characters to match filenames or perform other search and replace operations. But if the filename itself contains those special characters, then it could be a great nuisance. For dealing with such files we use escaping and quoting.
Escaping means providing a backslash (\) before the wild card so that its special meaning could be removed. For example, if we want to remove a file named chap*, then using the command rm chap* will delete all the file beginning with a prefix ’chap’. In this situation, we can use the following command,

$  rm chap\*

2. Enclosing the wild card or the entire pattern within quotes is called ___
a) escaping
b) quoting
c) listing
d) pattern matching
View Answer

Answer: b
Explanation: There is another way to turn off the meaning of the metacharacter. When a command argument is enclosed in quotes, the meaning of all special characters is turned off. This method is called quoting. For example,

advertisement
advertisement
$ echo ‘\’        //displays a \

3. To remove the file named my document.txt, which one of the following commands will be used?
a) rm my\ document.txt
b) rm my document.txt
c) rm *
d) rm my_document.txt
View Answer

Answer: a
Explanation: Apart from metacharacters, there are other characters that are special like the space character. The shell uses it to delimit command line arguments. So to remove the file my document.txt we can use escaping. The backslash will make the shell to ignore the space. Hence file will be removed easily.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. We can escape the \ itself using escaping.
a) True
b) False
View Answer

Answer: a
Explanation: Sometimes we may need to interpret the \ itself literally. To do so we need another \ before it. For example,

$ echo \\        // displays \

5. For escaping the newline character we can use ____
a) /
b) \
c) ?
d) \n
View Answer

Answer: b
Explanation: The newline character is also special, it marks the end of the command line. Some command lines that uses several arguments can be long enough to overflow to the next line. To split the wrapped line into two lines, make sure you input a \ before pressing [Enter].
advertisement

6. The output of the following command is ______________

advertisement
$ echo ‘The special character $ echo hello and | ls chap*’

a) undefined output
b) erroneous
c) hello
d) The special character $ echo hello and | ls chap*
View Answer

Answer: d
Explanation: Quoting is another way to turn off the meaning of a meta-character. When a command argument is enclosed in quotes, the meanings of all enclosed special characters are turned off.

7. Double quotes are more permissive than single quotes and allow the evaluation of the $ and ` itself.
a) True
b) False
View Answer

Answer: a
Explanation: When a command argument is enclosed in single quotes, the meaning of all enclosed special characters is turned off. But when we enclose the same in double quotes, we cannot protect the $ and ` (backquote). For example,

$ echo ‘$SHELL’      // displays $SHELL
$ echo “$SHELL”     // evaluates $SHELL and then display

8. Which of the following command will remove the file named * ?
a) rm *
b) rm ‘*’
c) rm \*
d) rm ‘*’ and rm \*
View Answer

Answer: d
Explanation: To suppress the nature of wildcard * we can use either escaping or quoting. The \ symbol will suppress the feature of wildcard and will remove the file named *. Similarly using quoting we can turn off the meaning of the meta character.

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of Unix for tests, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.