Linux OS Shell Question:
Download Questions PDF

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
a) only first string will print without any error
b) only second string will print without any error
c) both strings will print
d) none of the mentioned

Linux Shell Interview Question
Linux Shell Interview Question

Answer:

d) none of the mentioned
Explanation:
Function must be defined prior to call. Hence only first string will print and program will generate an error also.
Output:
root@ubuntu:/home/globalguideline# ./test.sh
Just call the function
./test.sh: 3: san_function: not found
root@ubuntu:/home/globalguideline#

Download Linux Shell Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

#!/bin/bash
function san_function1 {
echo "This is first function"
}
san_function2() {
echo "This is second function"
}
san_function1
san_function2
exit 0
a) This is the first function
b) This is the second function
c) This is the first function
This is the second function
d) program will generate error because first function definition is not correct
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
a) This is the first function
This is the second function
This is the third function

b) This is the first function
This is the third function
This is the second function

c) This is the second function
This is the first function
This is the third function

d) This is the third function
This is the first function
This is the second function