3. What is the output of this program?

#!/bin/bash
san_var=hello
readonly san_var
san_var=hi
echo $san_var
exit 0
a) hello
b) hi
c) nothing will print
d) none of the mentioned

a) hello
Explanation:
After the execution of the 'readonly' command, shell will not provide the permission to overwrite the value stored in variable 'san_var'.
Output:
root@ubuntu:/home/google# ./test.sh
./test.sh: line 4: san_var: readonly variable
hello
root@ubuntu:/home/google#

4. What is the output of this program?

#!/bin/bash
var[1]=san_1
var[2]=san_2
var[3]=san_3
echo ${var[*]}
exit 0
a) san_1
b) san_2
c) san_3
d) san_1 san_2 san_3

d) san_1 san_2 san_3
Explanation:
All items of an array can be accessed by using ${[*]} or ${[@]}.
Output:
root@ubuntu:/home/google# ./test.sh
san_1 san_2 san_3
root@ubuntu:/home/google#

5. What is the output of this program?

#!/bin/bash
var1=10
$var1=20
echo $var1
exit 0
a) program will print 10
b) program will generate a warning message
c) program will print 20
d) both (a) and (b)

d) both (a) and (b)
Explanation:
The doller sign ($) is used to access a variable's value, not to define it.
Output:
root@ubuntu:/home/google# ./test.sh
./test.sh: line 3: 10=20: command not found
10
root@ubuntu:/home/google#

6. What is the output of this program?

#!/bin/bash
san_var="google"
echo "$san_var"
echo '$san_var'
echo '"$san_var"'
echo "'$san_var'"
echo $san_var
exit 0
a) google
$san_var
"$san_var"
'google'
$san_var
b) google
google
"google"
'google'
google
c) program will generate an error message
d) program will print nothing

a) google
$san_var
"$san_var"
'google'
$san_var

Explanation:
Using double quotes does not affect the substitution of the variable, while single quotes and backslash do.
Output:
root@ubuntu:/home/google# ./test.sh
google
$san_var
"$san_var"
'google'
$san_var
root@ubuntu:/home/google#

8. Which one of the following is not a valid shell variable?
a) _san
b) san_2
c) _san_2
d) 2_san

d) 2_san
Explanation:
The shell variable can contain only letters(a to z or A to Z), numbers(0 to 9), or a underscore character(_) and a variable can not start with a number.