πŸ§ͺ Shell Scripting MCQ Quiz Hub

Shell Scripting Mcq Question Set 2

Choose a topic to test your knowledge and improve your Shell Scripting skills

The UNIX shell is both _______ and _______ language.





βœ… Correct Answer: 3

Which of the following function(s) are performed by an interactive shell?





βœ… Correct Answer: 4

Every feature used in an interactive shell can also be used by a shell script.





βœ… Correct Answer: 1

Which one of the following is arguably the best shell to use?





βœ… Correct Answer: 1

Which one of the following command is used to create a child shell?





βœ… Correct Answer: 3

Shell variables are of ____ types.





βœ… Correct Answer: 3

Suppose ABD_DIR is a local variable. Then it will be accessible to the child process.





βœ… Correct Answer: 2

____ command is used to display the environment variables only.





βœ… Correct Answer: 2

____ command displays all the variables available in the current shell.





βœ… Correct Answer: 2

Environment variable names can be defined only in uppercase.





βœ… Correct Answer: 2

Environment variables control the behavior of the system.





βœ… Correct Answer: 1

The shell has ____ prompts.





βœ… Correct Answer: 4

Which one of the following command will change our primary prompt from $ to C>?





βœ… Correct Answer: 1

Which environment variable is used to display our username?





βœ… Correct Answer: 3

Which one of the following is not an environment variable?





βœ… Correct Answer: 4

Which symbol is used for setting the PS1 prompt to show the current event number?





βœ… Correct Answer: 2

Which escape sequence is used with PS1 to show the hostname of our computer?





βœ… Correct Answer: 3

Which of the following shells support the use of aliases?





βœ… Correct Answer: 4

We can display an alias definition by using an alias with the name.





βœ… Correct Answer: 1

Which command is used in bash and Korn shells to display the previously used commands?





βœ… Correct Answer: 2

To display the last five used commands, which one of the following commands is used (in bash shell)?





βœ… Correct Answer: 1

Which of the following symbols are used for accessing previous commands by event numbers?





βœ… Correct Answer: 4

We can use relative addressing while executing previous commands.





βœ… Correct Answer: 1

We can also execute previous commands by context.





βœ… Correct Answer: 1

Which symbol is used as a shorthand for using the last argument to the previous command?





βœ… Correct Answer: 4

Shell enables one or more arguments to be obtained from the standard output of another command. This feature is called _____





βœ… Correct Answer: 1

Which of the following meta-character is used in command substitution?





βœ… Correct Answer: 1

Command substitution is enabled in single quotes also.





βœ… Correct Answer: 2

POSIX recommends the use of ____ instead of archaic `command ` for command substitution.





βœ… Correct Answer: 4

Which of the following shell doesn’t support the command substitution using $ recommended by POSIX?





βœ… Correct Answer: 4

Which symbol is used for assigning a value to variables?





βœ… Correct Answer: 3

Which symbol is used for evaluation of variables?





βœ… Correct Answer: 1

Which of the following is a correct initialization of variables to null strings?





βœ… Correct Answer: 4

A variable can be removed using _____





βœ… Correct Answer: 1

readonly command is used to protect a variable from reassignment.





βœ… Correct Answer: 1

C shell uses which command for assigning values to variables?





βœ… Correct Answer: 2

The variable assignment as x = 10 (whitespace on both sides of =) will work if we are not using C shell?





βœ… Correct Answer: 1

What will the result when we evaluate this statement? $ directory=’pwd’=`pwd`





βœ… Correct Answer: 1

Which of the following is not a system defined variable?





βœ… Correct Answer: 4

Which of the following is an invalid variable?





βœ… Correct Answer: 3

Command substitution requires the command to use _____





βœ… Correct Answer: 2

The command is valid. $ ls -lRa $HOME > home.ls





βœ… Correct Answer: 1

Which command runs the shell built-in command β€˜command’ with the given argument?





βœ… Correct Answer: 1

Which option of the command β€˜cd’ use the actual filesystem path for cd.. and the value of pwd?





βœ… Correct Answer: 4

Which command generates possible completions for string according to the and write it to standard output?





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

What is the output of this program? #!/bin/bash for i in 2 3 7 do echo "Sanfoundry" done exit 0





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 4

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





βœ… Correct Answer: 1

Functions improves the shell’s programmability significantly, because





βœ… Correct Answer: 1

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





βœ… Correct Answer: 4

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





βœ… Correct Answer: 4

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1