250+ TOP MCQs on Pattern Matching, Escaping and Quoting

Unix test on “Pattern Matching, Escaping and Quoting”.

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

Answer: a
Clarification: 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,

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

Answer: b
Clarification: 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,

$ 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

Answer: a
Clarification: 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.

  250+ TOP MCQs on Sed Command and Answers

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

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

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

Answer: b
Clarification: 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].

6. The output of the following command is ______________

$ 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*

Answer: d
Clarification: 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

Answer: a
Clarification: 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 *

  250+ TOP MCQs on Introduction to UNIX and Answers

Answer: d
Clarification: 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top