This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Shell Programming using Various Commands – 2”.
1. Which of the following option is used with a set for debugging shell scripts?
a) -a
b) -x
c) -d
d) -e
View Answer
Explanation: As we know that set command is used for assigning values to positional parameters, it also serves as debugging tool. For this purpose, we’ve to use -x option with it.
2. Suppose x =10, then what will be the value of x$x$?
a) undefined
b) erroneous
c) 100
d) x10$
View Answer
Explanation: Since x contains the value 10, and $ symbol is used with any variable for displaying its value. So $x will display 10. Hence the output will be x10$.
3. Given x=10 then,
x$x$ == $x$x.
The given statement is ____
a) True
b) False
View Answer
Explanation: x$x$ will be equal to x10$ and $x$x will be equal to 1010. Hence they are not equal.
4. A shell script stopped running when we change its name. Why?
a) location of the file changed
b) we can’t change the name of the script
c) $0 was used in the script
d) many possible reasons
View Answer
Explanation: A shell script will stop running when we change its name if we’d used the positional parameter $0 in it as $0 contains the name of the script file.
5. Where is the exit status of a command stored?
a) $0
b) $>
c) $1
d) $?
View Answer
Explanation: The exit status of a command is that particular value which is returned by the command to its parent. This value is stored in $?.
6. Which of the following is false?
a) here document provides standard input to any script non interactively
b) read command is used for making scripts interactive
c) $* stores the number of arguments specified
d) && and || are logical operators
View Answer
Explanation: The shell uses << symbol to read data from the same file containing the script. This is referred to as a here document. read command allows us to take input from the user to make the script interactive. && and || are logical operators which allow conditional execution. $* stores the complete set of positional parameters as a single string.
7. test statement cannot ______
a) compare two numbers
b) compare two strings
c) compare two files
d) check a file’s attributes
View Answer
Explanation: test works in three ways:
• compare two numbers
• compare two strings
• check a file’s attributes
8. ____ option is used with a test for checking if the file exists and has the size greater than zero.
a) -f
b) -r
c) -e
d) -s
View Answer
Explanation: test can also be used for performing various file tests like checking whether the file is a regular file, or is it readable, writable or executable. To check whether the file exists and has the size greater than zero, we have to use -s option with test. For example,
$ test -s filename
9. Every time shift command is used, the leftmost variable is lost.
a) True
b) False
View Answer
Explanation: shift statement is used for shifting the positional parameters to its immediate lower ones. Every time we use shift, the leftmost variable gets lost; s it should be saved in a variable before using shift.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Unix Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check Computer Science Books
- Practice MCA MCQs