|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
Thanks! |
|
#4
|
||||
|
||||
|
-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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|