Wednesday, July 27, 2022

[SOLVED] 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
Answer Checked By - David Goodson (WPSolving Volunteer)