Linux Bash Shell Questions & Answers – Built-in Commands – 3

This set of 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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 Sanfoundry"
  3.    read var
  4.    if $var=s
  5.    then
  6.    echo "Sanfoundry"
  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
View Answer

Answer: c
Explanation: The condition of if statement must be in square brackets.
Output:
root@ubuntu:/home/sanfoundry#./test.sh
press ‘s’ to print Sanfoundry
s
./test.sh: line 4: s=s: command not found
You did not press s

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

advertisement
  1.    #!/bin/bash
  2.    echo "How many times you want to print 'Sanfoundry'"
  3.    read value
  4.    for ((i=0;i<$value;i++))
  5.    do
  6.    echo "Sanfoundry";
  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
View Answer

Answer: a
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.sh
How many times you want to print ‘Sanfoundry’
4
Sanfoundry
Sanfoundry
Sanfoundry
Sanfoundry
root@ubuntu:/home/sanfoundry#
advertisement

7. What is the output of this program?

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

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

Answer: a
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.sh
Sanfoundry
Sanfoundry
Sanfoundry
root@ubuntu:/home/sanfoundry#

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
View Answer

Answer: a
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.sh
hi
Try to come out of the loop
hey
Try to come out of the loop
hello
Welcome
root@ubuntu:/home/sanfoundry#

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
View Answer

Answer: d
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.sh
Which file do you want to check
san.c
The file does not exist. Do you want to create? y/n
n
The file does not exist. Do you want to create? y/n
n
The file does not exist. Do you want to create? y/n
y
Your file has been created successfully.
The file is present in this directory
root@ubuntu:/home/sanfoundry# ls
san.c test2.txt test2.txt~ test.sh test.sh~ test.txt test.txt~
root@ubuntu:/home/sanfoundry#

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
View Answer

Answer: a
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.sh
Please enter a number
1000
It is greater than 1000
root@ubuntu:/home/sanfoundry#

Sanfoundry Global Education & Learning Series – Linux Administration & Programming.

Here’s the list of Best Books in Linux Commands & Shell Programming.
Here’s the list of Best Books in Linux Kernel, Device-Drivers & System Programming.

To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.

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.