Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-03-2012
Registered User
 

Join Date: Jun 2009
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
redirect for "[: : integer expression expected" error

Hi, I read in this forum that for "[: : integer expression expected" error, redirect the error message (2> /dev/null ) which can hide it.. is this a proper solution for the problem.. please let me know?

http://www.unix.com/shell-programmin...xpression.html

thanks!
Sponsored Links
    #2  
Old 02-03-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 

Join Date: Jun 2009
Location: Switzerland - ZH
Posts: 5,364
Thanks: 130
Thanked 542 Times in 475 Posts
It may be desirable or necessary at times to get rid of standard error in this way, but in the case you point to, "proper" would be to fix the code.
Sponsored Links
    #3  
Old 02-03-2012
Registered User
 

Join Date: Jun 2009
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
in my script, I am comparing the date values.. when DATE_OF_RUN_DB can't be a no value, Actual_Date can have no value.. and this is where I get the
"[: : integer expression expected" error.

code

HTML Code:
if  [ "${Actual_Date}" -lt "${DATE_OF_RUN_DB}"  ]
then
echo "Files older than last processed date are available in landing directory" >>${logfile} 2>&1
exit 1
fi
How do I avoid the error message? Should I redirect it to /dev/null or should I add another If then only if Actual_Date has a value, proceed for this IF loop for comparison?

Thanks!
    #4  
Old 02-03-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 

Join Date: Jun 2009
Location: Switzerland - ZH
Posts: 5,364
Thanks: 130
Thanked 542 Times in 475 Posts
-lt is a numeric operator. What format are these dates in? The best format for numerical comparison of dates is always YYYYMMDDHHMMSS . Can you change the dates to this format?
Sponsored Links
    #5  
Old 02-03-2012
Registered User
 

Join Date: Jun 2009
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
date values are in YYYYMMDD.. there is no timestamp part for the date fields.. how do I add timestamp to date values? if one of the date values can be empty which is a valid scenario in my case, how do I avoid the error message?
Sponsored Links
    #6  
Old 02-03-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 

Join Date: Jun 2009
Location: Switzerland - ZH
Posts: 5,364
Thanks: 130
Thanked 542 Times in 475 Posts
OK, nice. It's the format that makes it easy, so the timestamp doesn't matter (you can miss off less significant parts (from both numbers) without breaking a numerical comparison).

A couple of possible options:


Code:
if  [[ "${Actual_Date}" -lt "${DATE_OF_RUN_DB}"  ]]

if your shell supports it, or

Code:
if  [ "${Actual_Date:-0}" -lt "${DATE_OF_RUN_DB:-0}"  ]

although I have to say, I don't get an error for an unset variable when it's quoted in the test. You must be using Solaris
Sponsored Links
    #7  
Old 02-03-2012
Registered User
 

Join Date: Jun 2009
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
thanks Scott, that works

I am on LINUX.

actually, as it is a date value, should n't I use the defaule date - ex 00010101 instead of 0 with which it can't compare another date value..

I mean only the ACTUAL_DATE can or can't have values... the DATE_OF_RUN_DB should have a valida date value.. so if I default ACTUAL_DATE to 0, will it not throw an error?
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error: integer expression expected fed.linuxgossip Shell Programming and Scripting 2 06-09-2011 03:21 PM
cshell integer expression from "0000" to "1999" rockytodd Shell Programming and Scripting 3 11-04-2010 06:09 AM
"integer expression expected" error with drive space monitoring script wbdevilliers UNIX for Dummies Questions & Answers 2 01-05-2010 07:47 AM
error "integer expression expected" when selecting values jorlando Shell Programming and Scripting 4 12-10-2008 03:31 PM
integer expression expected error dark_knight Shell Programming and Scripting 2 10-15-2008 11:07 AM



All times are GMT -4. The time now is 03:40 AM.