250+ TOP MCQs on Built-in Commands and Answers

Linux / Unix questions and answers focuses on Built-in Commands in Linux Bash Shell. This is set-3.1. Which command runs the shell built-in command ‘command’ with the given argument?
a) builtin
b) caller
c) there is no command present for this purpose
d) none of the mentioned

Answer: a
Clarification: None.

2. Which option of the command ‘cd’ use the actual filesystem path for cd.. and the value of pwd?
a) -l
b) -L
c) -p
d) -P

Answer: d
Clarification: None.

3. Which command generates possible completions for string according to the and write it to standard output?
a) compgen
b) complete
c) continue
d) none of the mentioned

Answer: a
Clarification: None.

4. Which command executes ‘command’ in place of the current process instead of creating a new process?
a) exec
b) command
c) trap
d) none of the mentioned

Answer: a
Clarification: None.

5. After running this program, as you press ‘s’, what will be the output of the program?

  1.    #!/bin/bash
  2.    echo "press 's' to print "
  3.    read var
  4.    if $var=s
  5.    then
  6.    echo ""
  7.    else
  8.    echo "You did not press s"
  9.    fi
  10.    exit 0

a) Sanfoudry
b) You did not press s
c) Program will generate an error message
d) None of the mentioned

Answer: c

6. After running this program, as your press 4, what will be the output of the program?

  1.    #!/bin/bash
  2.    echo "How many times you want to print ''"
  3.    read value
  4.    for ((i=0;i<$value;i++))
  5.    do
  6.    echo "";
  7.    done
  8.    exit 0

a) ‘Sanfoudry’ will print 4 times
b) ‘Sanfoudry’ will print 3 times
c) ‘Sanfoudry’ will print 5 times
d) Program will generate an error message

Answer: a

7. What is the output of this program?

  1.    #!/bin/bash
  2.    for i in 2 3 7
  3.    do
  4.    echo ""
  5.    done
  6.    exit 0

a) ‘’ will print 3 times
b) Nothing will print
c) Program will generate an error message
d) None of the mentioned

Answer: a

8. How can you come out of the loop in this program?

  1.    #!/bin/bash
  2.    read x
  3.    while [ $x != "hello" ]
  4.    do
  5.    echo "Try to come out of the loop"
  6.    read x
  7.    done
  8.    echo "Welcome"
  9.    exit 0

a) by entering “hello”
b) by entering anything except “hello”
c) it is not possible
d) none of the mentioned

Answer: a

9. What is the output of this program?

  1.    #!/bin/bash
  2.    echo "Which file do you want to check"
  3.    read x
  4.    until [ -e $x ]
  5.    do
  6.    echo "The file does not exist. Do you want to create? y/n"
  7.    read a
  8.    if [ $a = y ]; then
  9.    touch $x
  10.    echo "Your file has been created successfully."
  11.    fi
  12.    done
  13.    echo "The file is present in this directory"
  14.    exit 0

a) it checks the existance of your entered file in the present working directory
b) it creates the file if file does not exists
c) program runs untill you create the file
d) all of the mentioned

Answer: d
10. After running this program, if you enter 1000, then what will be the output of the program?
  1. 	#!/bin/bash
  2. 	echo "Please enter a number"
  3. 	read a
  4. 	if [ $a -lt 100 ]; then
  5. 	echo "It is less than 100";
  6. 	elif [ $a -lt 1000 ]; then
  7. 	echo "It is less than 1000"
  8. 	else
  9. 	echo "It is greater than 1000"
  10. 	fi
  11. 	exit 0

a) It is greater than 1000
b) It is less then 1000
c) It is equal to 1000
d) None of then mentioned

Answer: a

Leave a Reply

Your email address will not be published. Required fields are marked *