Linux Bash Arithmetic Expressions Question:
Download Questions PDF

What is the output of this program?
#!/bin/bash
a=10
b=$(( $a<0?10:$a<100 ))
echo $b
exit 0
a) 10
b) 20
c) 1
d) 0

Linux Bash Arithmetic Expressions Interview Question
Linux Bash Arithmetic Expressions Interview Question

Answer:

c) 1
Firstly the '$a<0' condition has been checked. Because it is false hence the right hand side condition of the colon (:) has been checked and this is true so program output is 1.

Download Linux Bash Arithmetic Expressions Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?
#!/bin/bash
a=10; b=20
c=$((++a))
let a=c+a
echo $a
exit 0
a) 21
b) 22
c) program will generate an error message
d) none of the above
What is the output of this program?
#!/bin/bash
a=10
b=$(( $a<0&&$a<100 ))
echo $b
exit 0
a) 10
b) 0
c) 1