read X
read Y
read Z
if [ $X = $Y = $Z ]
then
echo EQUILATERAL # ALL X, Y, Z ARE EQUAL
elif [[ $X = $Y || $X = $Z || $Y = $Z ]]
then
echo ISOSCELES # ONLY 2 VARIABLES ARE EQUAL
else
echo SCALENE # NONE IS EQUAL
fi
Well, I have two questions here, first is the usage of $X = $Y = $Z valid or not. Second, when I give an input of 3 similar variables it's printing ISOSCELES instead of EQUILATERAL. Is it a logic error, or the first part is not syntactically correct?
[ $X = $Y = $Z ]You need[ "$X" = "$Y" ] && [ "$Y" = "$Z" ]Always post your code to ShellCheck to fix minor issues like this first, then if you still have problems, post here.ifstatement.[ ... ]or withtest(synonymous). If you need a reference I like the man7.org pages, e.g. man 1 bash