Olete.in
Articles
Mock Tests
🧪 Shell Scripting MCQ Quiz Hub
Shell Scripting Mcq Question Set 2
Choose a topic to test your knowledge and improve your Shell Scripting skills
1. The UNIX shell is both _______ and _______ language.
interactive, responsive
interpreter, executing
scripting, interpreter
high level, low level
2. Which of the following function(s) are performed by an interactive shell?
job control
history
aliases
job control, history, aliases
3. Every feature used in an interactive shell can also be used by a shell script.
True
False
all of the above
None of the mentioned
4. Which one of the following is arguably the best shell to use?
Bash
Korn
C
Bourne
5. Which one of the following command is used to create a child shell?
fork
wait
sh
env
6. Shell variables are of ____ types.
1
3
2
4
7. Suppose ABD_DIR is a local variable. Then it will be accessible to the child process.
True
False
all of the above
None of the mentioned
8. ____ command is used to display the environment variables only.
set
env
sh
var divs = #("div");
9. ____ command displays all the variables available in the current shell.
env
set
var
shift
10. Environment variable names can be defined only in uppercase.
True
False
all of the above
None of the mentioned
11. Environment variables control the behavior of the system.
True
False
all of the above
None of the mentioned
12. The shell has ____ prompts.
1
4
many
2
13. Which one of the following command will change our primary prompt from $ to C>?
PS1=”C> “
PS2=”C>”
PS1=”>C”
PS2=”<C”
14. Which environment variable is used to display our username?
PATH
MAIL
LOGNAME
HOME
15. Which one of the following is not an environment variable?
HOME
PATH
USER
env
16. Which symbol is used for setting the PS1 prompt to show the current event number?
^
!
&
|
17. Which escape sequence is used with PS1 to show the hostname of our computer?
c
h
e
18. Which of the following shells support the use of aliases?
bourne
Korn
bash
Korn and bash
19. We can display an alias definition by using an alias with the name.
True
False
all of the above
None of the mentioned
20. Which command is used in bash and Korn shells to display the previously used commands?
his
history
sh
ps
21. To display the last five used commands, which one of the following commands is used (in bash shell)?
history 5
history -5
history
history 5-
22. Which of the following symbols are used for accessing previous commands by event numbers?
!
r
$
! and r
23. We can use relative addressing while executing previous commands.
True b) False
False
all of the above
None of the mentioned
24. We can also execute previous commands by context.
True
False
all of the above
None of the mentioned
25. Which symbol is used as a shorthand for using the last argument to the previous command?
%
_
|
$
26. Shell enables one or more arguments to be obtained from the standard output of another command. This feature is called _____
command substitution
argument substitution
shell substitution
korn
27. Which of the following meta-character is used in command substitution?
`
`
“
>
28. Command substitution is enabled in single quotes also.
True
False
all of the above
None of the mentioned
29. POSIX recommends the use of ____ instead of archaic `command ` for command substitution.
|
#
%
$
30. Which of the following shell doesn’t support the command substitution using $ recommended by POSIX?
Korn
bash
C
Bourne
31. Which symbol is used for assigning a value to variables?
$
&
=
@
32. Which symbol is used for evaluation of variables?
$
&
=
@
33. Which of the following is a correct initialization of variables to null strings?
x=
x=’ ‘
x=” “
x=, x=’ ‘, x=” “
34. A variable can be removed using _____
unset
readonly
del
Bash shell
35. readonly command is used to protect a variable from reassignment.
True
False
all of the above
None of the mentioned
36. C shell uses which command for assigning values to variables?
=
set
unset
$
37. The variable assignment as x = 10 (whitespace on both sides of =) will work if we are not using C shell?
True
FALSE
all of the above
None of the mentioned
38. What will the result when we evaluate this statement? $ directory=’pwd’=`pwd`
output of pwd command along with string pwd=
undefined output
erroneous
directory variable will hold string pwd
39. Which of the following is not a system defined variable?
$PATH
$HOME
$SHELL
$cd
40. Which of the following is an invalid variable?
_user
us01
-txtfile
txt123
41. Command substitution requires the command to use _____
standard input
standard input
standard error
All of the mentioned
42. The command is valid. $ ls -lRa $HOME > home.ls
True
False
all of the above
None of the mentioned
43. Which command runs the shell built-in command ‘command’ with the given argument?
builtin
caller
there is no command present for this purpose
none of the mentioned
44. Which option of the command ‘cd’ use the actual filesystem path for cd.. and the value of pwd?
-l
-L
-p
-P
45. Which command generates possible completions for string according to the and write it to standard output?
compgen
complete
continue
none of the mentioned
46. After running this program, as your press 4, what will be the output of the program? #!/bin/bash echo "How many times you want to print 'Sanfoundry'" read value for ((i=0;i<$value;i++)) do echo "Sanfoundry"; done exit 0
‘Sanfoudry’ will print 4 times
‘Sanfoudry’ will print 3 times
‘Sanfoudry’ will print 5 times
Program will generate an error message
47. What is the output of this program? #!/bin/bash for i in 2 3 7 do echo "Sanfoundry" done exit 0
‘Sanfoundry’ will print 3 times
Nothing will print
Program will generate an error message
none of the mentioned
48. How can you come out of the loop in this program? #!/bin/bash read x while [ $x != "hello" ] do echo "Try to come out of the loop" read x done echo "Welcome" exit 0
by entering “hello”
by entering anything except “hello”
it is not possible
None of the mentioned
49. What is the output of this program? #!/bin/bash echo "Which file do you want to check" read x until [ -e $x ] do echo "The file does not exist. Do you want to create? y/n" read a if [ $a = y ]; then touch $x echo "Your file has been created successfully." fi done echo "The file is present in this directory" exit 0
it checks the existance of your entered file in the present working directory
it creates the file if file does not exists
program runs untill you create the file
All of the Mentioned
50. After running this program, if you enter 1000, then what will be the output of the program? #!/bin/bash echo "Please enter a number" read a if [ $a -lt 100 ]; then echo "It is less than 100"; elif [ $a -lt 1000 ]; then echo "It is less than 1000" else echo "It is greater than 1000" fi exit 0
It is greater than 1000
It is less then 1000
It is equal to 1000
None of then mentioned
51. Functions improves the shell’s programmability significantly, because
when we invoke a function, it is already in the shell’s memory, therefore a function runs faster than seperate scripts
function will not provides a piece of code for repetative tasks
all of the mentioned
None of the mentioned
52. What is the output of this program? #!/bin/sh san_function() { echo "Welcome to the Sanfoundry" printf "World of Linux " } unset -f san_function san_function exit 0
Welcome to the Sanfoundry
World of Linux
both Welcome to the Sanfoundry and World of Linux
nothing will print
53. What is the output of this program? #!/bin/sh echo "Just call the function" san_function san_function() { echo "This is a function" } exit 0
only first string will print without any error
only second string will print without any error
both strings will print
None of the mentioned
54. What is the output of this program? #!/bin/sh san_function1() { a=5 echo "This is the first function" san_function2 } san_function2() { echo "This is the second function" san_function3 } san_function3() { echo "This is the third function" } san_function1 exit 0
This is the first function This is the second function This is the third function
This is the first function This is the third function This is the second function
This is the second function This is the first function This is the third function
This is the third function This is the first function This is the second function
55. The user bhojas logged in and performed the following sequence of command. What will be the output of the last command? $ cd project/module1 $ pwd
/home/bhojas/project/module1
/home/project/module1
/usr/bhojas/project/module1
project/module1
Submit