Linux OS Shell Question:
Download Questions PDF

What is the output of this program?

#!/bin/sh
var="google"
san_function() {
var="Linux"
echo $var
}
san_function
exit 0
a) google
b) Linux
c) command not found
d) none of the mentioned

Linux Shell Interview Question
Linux Shell Interview Question

Answer:

b) Linux
Explanation:
If local variable name is same as the global variable, it overlays the variable, but only within the function.
Output:
root@ubuntu:/home/google# ./test.sh
Linux
root@ubuntu:/home/google#

Download Linux Shell Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

#!/bin/sh
san_function() {
echo "Welcome to the google"
printf "World of Linuxn"
}
unset -f san_function
san_function
exit 0
a) Welcome to the google
b) World of Linux
c) both (a) and (b)
d) nothing will print
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