Unix Questions and Answers – Shell Offerings

This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Shell Offerings”.

1. set command by default displays the variables in the current shell.
a) True
b) False
View Answer

Answer: a
Explanation: The set statement by default displays the variables in the current shell, but in bash and Korn shell, it can make several environment settings with -o option.

2. Which one of the following keyword is used with the set command to avoid overwrite existing file?
a) nooverwrite
b) ignore
c) clobber
d) noclobber
View Answer

Answer: d
Explanation: The shell’s > symbol overwrites (clobber) an existing file, and to prevent such accidental overwriting, e have to use noclobber argument in the following way:

$ set  -o  noclobber        // no more overwriting file with >

advertisement
advertisement

3. To prevent accident logging out, we can use ____ as a keyword with the set command.
a) noclobber
b) log out
c) ignoreeof
d) ignore
View Answer

Answer: c
Explanation: It may happen that sometimes when we press the Ctrl-d with intent to terminate standard input, but end up logging out of the system. The ignoreeof keyword offers protection from accidental logging out.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ set  -o  ignoreeof        //no more logging out using ctrl-d

4. To reverse any setting updated by set command we can use ____ symbol.
a) –
b) /
c) +
d) $
View Answer

Answer: c
Explanation: A set option is turned off with set +o keyword. For example, to reverse the noclobber feature use the following command:

advertisement
$ set +o noclobber.

5. The ____ acts as a shorthand representation of the home directory.
a) $
b) ~
c) “”
d) %
View Answer

Answer: b
Explanation: The ~ acts as a shorthand representation of the home directory. When the ~ (tidle) is followed by a login name, the shell understands the entire argument as the absolute pathname of the login directory. Thus when the shell encounters the following command line, it switches the Sharma’s home directory.

advertisement
$ cd ~ sharma         //effectively becomes $HOME/sharma

6. Every shell uses at least one startup script in the user’s home directory, which is executed when the user logs in.
a) True
b) False
View Answer

Answer: a
Explanation: Every shell uses at least one startup script in the user’s home directory. This script is executed when the user logs in. Some shells also make use of a separate file that is run before logging out. We can look for these files in our home directory.

.profile (Bourne shell)
.profile and .kshrc (Korn shell)
.bash_profile or .bashrc (bash shell)

7. Which file is executed every time a second shell is called up?
a) .profile
b) rc file
c) .script
d) env.file
View Answer

Answer: b
Explanation: There is no rc file in Bourne, but bash and Korn shell use one. This file is defined by an environment variable (BASH_ENV in bash and ENV in Korn). This rc file is executed every time a second shell is called up (when running a shell script, for instance).

8. Which of the following are history variables?
a) HISTISIZE
b) HISTFILESIZE
c) HISTORY
d) HISTISIZE and HISTFILESIZE
View Answer

Answer: d
Explanation: The history list is maintained in memory. Bash uses two separate variables HISTSIZE and HISTFILESIZE for setting the size of the history list in memory and on disk. For example,

$ HISTSIZE=500                      // bash and Korn
$ HISTFILESIZE=1000                // bash only -determines the size of disk file

9. Which one of the following command will search history list for the previous command having the last occurrence of string cvf?
a) /cvf
b) /cvf [enter]
c) /bkw
d) !cvf
View Answer

Answer: a
Explanation: We can also use vi’s search technique to recall previous commands from the history list. Even we can also search in the reverse direction, using /pattern sequence.

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of 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.