If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Error in IF Condtion .. Need Help!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-30-09, 10:14
SeenuGuddu SeenuGuddu is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
Error in IF Condtion .. Need Help!

what is the syntax error in this
Code:
if [[ ${CYC_DT} -ge ${cur_sys_dt}]]; then
  echo "cycle date is equal"
else
  echo "not equal"
fi
t.ksh[120]: Syntax error at line 283 : `then' is not expected.

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-31-09, 10:32
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,230
That depends on the contents of the two variables. You may also want to insert a space before "]]".
Reply With Quote
  #3 (permalink)  
Old 10-31-09, 14:37
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
I believe I've fixed most of the syntax errors below. You are also testing to see if $CYC_DT is greater or equal to $cur_sys_dt but then reporting that it is just equal, use -eq if you want to test equality between numbers. Also if either of these variables don't have a value then you'll get a syntax error. Otherwise it's fine
Code:
if [ $CYC_DT -ge $cur_sys_dt ]
then
   echo "cycle date is equal"
else
   echo "not equal"
fi

Last edited by mike_bike_kite; 10-31-09 at 14:56.
Reply With Quote
  #4 (permalink)  
Old 11-02-09, 04:48
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,578
I always enclose variables in conditions double-quotes to avoid semantic changes, depending on the variable content. (For SQL, you would say to avoid SQL injection.)
Code:
if [ "$CYC_DT" -ge "$cur_sys_dt" ]
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On