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
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
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,
$ 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
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.
4. We can escape the \ itself using escaping.
a) True
b) False
View Answer
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
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].
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*
View Answer
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
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
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]
- Check Computer Science Books
- Practice MCA MCQs
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check MCA Books