Linux OS Shell Question:
Download Questions PDF

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)

Linux Shell Interview Question
Linux Shell Interview Question

Answer:

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#

Download Linux Shell Interview Questions And Answers PDF

Previous QuestionNext Question
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
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