Unix Questions and Answers – Shell Programming using Various Commands – 2

This set of Unix Technical Questions & Answers 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

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

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

advertisement
advertisement
x$x$ == $x$x.

The given statement is ____
a) True
b) False
View Answer

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

Answer: c
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

Answer: d
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 $?.
advertisement

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

Answer: c
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

Answer: c
Explanation: test works in three ways:
• compare two numbers
• compare two strings
• check a file’s attributes
advertisement

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

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

Answer: a
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 technical questions on Unix, 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.