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 online now Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 27 May 2015, 5:40 PM EDT
Location: Toronto, Canada
Posts: 2,883
Thanks: 0
Thanked 119 Times in 107 Posts
Quote:
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 ]
then
echo "------------"

fi

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):


Code:
if [ ${j:-0} -lt 50 ]