hi
i am trying to compare a value with value 50. but i am getting
"[: -lt: unary operator expected"
I am using
if [ $j -lt 50 ]
then
echo "------------"
fi
please help
thanks in advance
Satya
hi
i am trying to compare a value with value 50. but i am getting
"[: -lt: unary operator expected"
I am using
if [ $j -lt 50 ]
then
echo "------------"
fi
please help
thanks in advance
Satya
If $j has no value at all, the expression will be invalid because it will vanish entirely, making it look like just [ -j 50 ]. Wrap $j in double-quotes and it won't vanish, becoming [ "" -lt 50 ] , which still isn't altogether sensible -- comparing a blank string to an integer -- but at least has correct syntax.
Make sure that $j expands to a value. Best is to set it explicitly, but you can also give it a default value (0 in this example):
if [ ${j:-0} -lt 50 ]