Unix/Linux Go Back    

unary operator expected

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member cfajohnson Regarding:
unary operator expected.
Please Follow The Primary Link Above to View the Full Discussion.

Old Unix and Linux 03-06-2009
cfajohnson's Unix or Linux Image
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
Join Date: Mar 2007
Last Activity: 8 September 2015, 12:32 AM EDT
Location: Toronto, Canada
Posts: 2,896
Thanks: 0
Thanked 131 Times in 116 Posts
Originally Posted by Satyak View Post
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 ]
echo "------------"


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 ]