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
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
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
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
Explanation: None.
5. After running this program, as you press ‘s’, what will be the output of the program?
#!/bin/bash
echo "press 's' to print Sanfoundry"
read var
if $var=s
then
echo "Sanfoundry"
else
echo "You did not press s"
fi
exit 0
a) Sanfoudry
b) You did not press s
c) Program will generate an error message
d) None of the mentioned
View Answer
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?
#!/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
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
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#
7. What is the output of this program?
#!/bin/bash
for i in 2 3 7
do
echo "Sanfoundry"
done
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
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?
#!/bin/bash
read x
while [ $x != "hello" ]
do
echo "Try to come out of the loop"
read x
done
echo "Welcome"
exit 0
a) by entering “hello”
b) by entering anything except “hello”
c) it is not possible
d) none of the mentioned
View Answer
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?
#!/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
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
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?
#!/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
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
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.
- Buy Linux Books
- Apply for Linux Internship
- Practice Programming MCQs
- Apply for Programming Internship
- Buy Information Technology Books