Shell Scripting/Shell Scripting Mcq Question Set 2 Sample Test,Sample questions

Question:
 A variable can be removed using _____

1.unset

2.readonly

3.del

4. Bash shell

Posted Date:-2022-01-28 08:06:29


Question:
 C shell uses which command for assigning values to variables?

1.=

2. set

3. unset

4.$

Posted Date:-2022-01-28 08:07:09


Question:
 readonly command is used to protect a variable from reassignment.

1.True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:06:48


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

1. True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:10:22


Question:
 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

1. /home/bhojas/project/module1

2. /home/project/module1

3./usr/bhojas/project/module1

4. project/module1

Posted Date:-2022-01-28 08:47:31


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

1.history 5

2. history -5

3.history

4. history 5-

Posted Date:-2022-01-28 07:59:29


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

1.x=

2. x=’ ‘

3.x=” “

4.x=, x=’ ‘, x=” “

Posted Date:-2022-01-28 08:06:05


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

1.PS1=”C> “

2.PS2=”C>”

3.PS1=”>C”

4. PS2=”<C”

Posted Date:-2022-01-28 07:56:04


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

1.%

2. _

3.|

4. $

Posted Date:-2022-01-28 08:01:01


Question:
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

1.‘Sanfoudry’ will print 4 times

2.‘Sanfoudry’ will print 3 times

3.‘Sanfoudry’ will print 5 times

4.Program will generate an error message

Posted Date:-2022-01-28 08:18:47


Question:
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

1.It is greater than 1000

2.It is less then 1000

3. It is equal to 1000

4.None of then mentioned

Posted Date:-2022-01-28 08:20:36


Question:
Command substitution is enabled in single quotes also.

1.True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:04:03


Question:
Command substitution requires the command to use _____

1. standard input

2. standard input

3. standard error

4. All of the mentioned

Posted Date:-2022-01-28 08:09:52


Question:
Environment variable names can be defined only in uppercase.

1.True

2. False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 07:54:05


Question:
Environment variables control the behavior of the system.

1.True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 07:54:23


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

1.True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 07:50:47


Question:
Functions improves the shell’s programmability significantly, because

1. when we invoke a function, it is already in the shell’s memory, therefore a function runs faster than seperate scripts

2.function will not provides a piece of code for repetative tasks

3. all of the mentioned

4.None of the mentioned

Posted Date:-2022-01-28 08:25:19


Question:
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

1.by entering “hello”

2.by entering anything except “hello”

3. it is not possible

4.None of the mentioned

Posted Date:-2022-01-28 08:19:42


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

1.|

2. #

3.%

4.$

Posted Date:-2022-01-28 08:04:27


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

1.command substitution

2.argument substitution

3.shell substitution

4. korn

Posted Date:-2022-01-28 08:03:21


Question:
Shell variables are of ____ types.

1.1

2.3

3.2

4.4

Posted Date:-2022-01-28 07:51:59


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

1. True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 07:52:17


Question:
The shell has ____ prompts.

1.1

2.4

3.many

4.2

Posted Date:-2022-01-28 07:54:44


Question:
The UNIX shell is both _______ and _______ language.

1. interactive, responsive

2. interpreter, executing

3.scripting, interpreter

4. high level, low level

Posted Date:-2022-01-28 07:49:56


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

1.True

2. FALSE

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:07:28


Question:
We can also execute previous commands by context.

1. True

2.False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:00:34


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

1.True

2. False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 07:58:44


Question:
We can use relative addressing while executing previous commands.

1.True b) False

2. False

3.all of the above

4.None of the mentioned

Posted Date:-2022-01-28 08:00:14


Question:
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

1.it checks the existance of your entered file in the present working directory

2.it creates the file if file does not exists

3. program runs untill you create the file

4.All of the Mentioned

Posted Date:-2022-01-28 08:20:10


Question:
What is the output of this program?

   #!/bin/bash
   for i in 2 3 7
   do
   echo "Sanfoundry"
   done
   exit 0

1. ‘Sanfoundry’ will print 3 times

2. Nothing will print

3. Program will generate an error message

4. none of the mentioned

Posted Date:-2022-01-28 08:19:19


Question:
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

1.only first string will print without any error

2. only second string will print without any error

3.both strings will print

4.None of the mentioned

Posted Date:-2022-01-28 08:26:24


Question:
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

1.Welcome to the Sanfoundry

2.World of Linux

3.both Welcome to the Sanfoundry and World of Linux

4.nothing will print

Posted Date:-2022-01-28 08:25:47


Question:
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

1.This is the first function This is the second function This is the third function

2.This is the first function This is the third function This is the second function

3.This is the second function This is the first function This is the third function

4.This is the third function This is the first function This is the second function

Posted Date:-2022-01-28 08:26:58


Question:
What will the result when we evaluate this statement?

$ directory=’pwd’=`pwd`

1.output of pwd command along with string pwd=

2.undefined output

3.erroneous

4.directory variable will hold string pwd

Posted Date:-2022-01-28 08:07:51


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

1.compgen

2. complete

3.continue

4. none of the mentioned

Posted Date:-2022-01-28 08:18:12


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

1. his

2.history

3.sh

4.ps

Posted Date:-2022-01-28 07:59:07


Question:
Which command runs the shell built-in command ‘command’ with the given argument?

1. builtin

2.caller

3.there is no command present for this purpose

4. none of the mentioned

Posted Date:-2022-01-28 08:17:23


Question:
Which environment variable is used to display our username?

1.PATH

2.MAIL

3. LOGNAME

4.HOME

Posted Date:-2022-01-28 07:56:42


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

1.

2.c

3.h

4. e

Posted Date:-2022-01-28 07:58:04


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

1. job control

2.history

3.aliases

4. job control, history, aliases

Posted Date:-2022-01-28 07:50:26


Question:
Which of the following is an invalid variable?

1._user

2.us01

3.-txtfile

4.txt123

Posted Date:-2022-01-28 08:09:28


Question:
Which of the following is not a system defined variable?

1.$PATH

2.$HOME

3. $SHELL

4.$cd

Posted Date:-2022-01-28 08:08:14


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

1. `

2. `

3.“

4.>

Posted Date:-2022-01-28 08:03:45


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

1.Korn

2.bash

3. C

4.Bourne

Posted Date:-2022-01-28 08:04:48


Question:
Which of the following shells support the use of aliases?

1.bourne

2.Korn

3.bash

4.Korn and bash

Posted Date:-2022-01-28 07:58:27


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

1.!

2. r

3.$

4.! and r

Posted Date:-2022-01-28 07:59:53


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

1.fork

2. wait

3.sh

4.env

Posted Date:-2022-01-28 07:51:37


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

1.Bash

2.Korn

3. C

4.Bourne

Posted Date:-2022-01-28 07:51:11


Question:
Which one of the following is not an environment variable?

1. HOME

2.PATH

3.USER

4.env

Posted Date:-2022-01-28 07:57:06


Question:
Which option of the command ‘cd’ use the actual filesystem path for cd.. and the value of pwd?

1.-l

2. -L

3.-p

4. -P

Posted Date:-2022-01-28 08:17:48


Question:
Which symbol is used for assigning a value to variables?

1. $

2.&

3. =

4.@

Posted Date:-2022-01-28 08:05:14


Question:
Which symbol is used for evaluation of variables?

1.$

2. &

3.=

4.@

Posted Date:-2022-01-28 08:05:40


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

1. ^

2.!

3. &

4. |

Posted Date:-2022-01-28 07:57:40


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

1.env

2.set

3.var

4.shift

Posted Date:-2022-01-28 07:53:46


Question:
____ command is used to display the environment variables only.

1.set

2. env

3.sh

4.var divs = #("div");

Posted Date:-2022-01-28 07:53:18


More MCQS

  1. Shell Scripting Mcq Question Set 1
  2. Shell Scripting Mcq Question Set 2
  3. Shell Scripting Mcq Question Set 3
  4. Shell Scripting Mcq Question Set 4
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!