a=10
b=20
c=30
if [[ $a -gt $b && $a -gt $c ]]
then
echo "A is the greater number"
if [[ $b -gt $a && $b -gt $c ]]
then
echo "B is the greater number"
else
echo "C is the greate number"
fi
I tried doing dos2unix formatting, adding another ‘fi’ but still code throwing same error
EDIT by Ed Morton: here’s your code with common indenting:
a=10
b=20
c=30
if [[ $a -gt $b && $a -gt $c ]]
then
echo "A is the greater number"
if [[ $b -gt $a && $b -gt $c ]]
then
echo "B is the greater number"
else
echo "C is the greate number"
fi
I expect the problem is no longer a mystery if you format your code that way.
2
Answers
You have two
if
statements but only onefi
. Try usingelif
for your second case instead:It a better option to split test logic operators outside of brackets.
Here is an example of another implementation of your code: