Bash Shell no printed output after checking a -lt condition

Issue

I am trying to test if Variable X is less than 50, if yes then print it (echo it), but I am getting no output!

X=1
if [$X -lt 50]
then 
    echo $X
fi

Solution

Try with the following :

X=1
if [ "$X" -lt 50 ]
then 
    echo $X
fi

Whitespace matters in bash.

Answered By – edi9999

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published