[: 2016-02-29: integer expression expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [: 2016-02-29: integer expression expected
# 1  
Old 05-12-2016
[: 2016-02-29: integer expression expected

Hi All,

Seeking for your assistance on my error encountered below. I think there's no problem on my script but i'm encountering integer expression expected. i already put double quote on my variable but still the same error i encountered.


Code:
#!/bin/sh

TASKDATE=2016-02-10
VSQL_F="connect"

dProcDate=`${VSQL_F} <<-EOF
SELECT LAST_DAY('$TASKDATE') AS dProcDate FROM DUAL;
EOF`

dCurrent=`${VSQL_F} <<-EOF
SELECT LAST_DAY(SYSDATE) AS dCurrent FROM DUAL;
EOF`

dProcDate2=`${VSQL_F} <<-EOF
SELECT LAST_DAY(ADD_MONTHS(SYSDATE,-1)) AS dProcDate FROM DUAL;
EOF`

if [ "$dProcDate" -lt "$dCurrent" ]; then
$dProcDate
else
$dProcDate2
fi


echo $TASKDATE
echo $dProcDate
echo $dCurrent
echo $dProcDate2

Code:
Error encountered:
jpv2.sh: line 18: [: 2016-02-29: integer expression expected
jpv2.sh: line 21: 2016-04-30: command not found
2016-02-10
2016-02-29
2016-05-31
2016-04-30

please advise,
# 2  
Old 05-12-2016
Convert your date to seconds and then compare.
Code:
dProcDate="2016-02-29"
dCurrent="2016-05-31"

dProcDate_sec=$(date -d"$dProcDate" '+%s')
dCurrent_sec=$(date -d"$dCurrent" '+%s')

if [ $dProcDate_sec -le $dCurrent_sec ]; then
echo $dProcDate
else
echo $dProcDate2
fi

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 05-12-2016
oks will try

---------- Post updated at 04:10 PM ---------- Previous update was at 03:59 PM ----------

thanks sir pravin27. how come it's working. why do i need to convert it to sec?

Thanks,
# 4  
Old 05-12-2016
You need convert it to seconds so you can use comparison operator in condition. Date format (2016-02-28) is not an integer , that's why script was throwing an error.
# 5  
Old 05-12-2016
Since they're YYYY-MM-DD strings, you could also just compare them as strings.

Code:
if [ "$STRING1" "<" "$STRING2" ]
then
...
fi

You must put quotes around < > etc. or they will be taken as redirection operators.
# 6  
Old 05-12-2016
Quote:
Originally Posted by Corona688
Since they're YYYY-MM-DD strings, you could also just compare them as strings.

Code:
if [ "$STRING1" "<" "$STRING2" ]
then
...
fi

You must put quotes around < > etc. or they will be taken as redirection operators.
That will work with some shells (and with some versions of the stand-alone
Code:
test

/[ utilities), but the only string comparison operators defined for test in the standards are = and !=.

We know that the submitter is using /bin/sh, but that isn't enough to know what operating system is being used nor what shell has been designated as /bin/sh on the submitter's system.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 05-13-2016
For string comparison I prefer the [[ compound ]], supported by ksh/bash/zsh, and no fancy quoting:
Code:
if [[ $dProcDate < $dCurrent ]]
then
  echo older
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Integer expression expected

Hello , This is the piece of the code which is giving me trouble if ;then exit_proc "${SOURCEDIR}/${OUT_FILE} does not exists or not readable" 2 else word_count=`wc -l < ${SOURCEDIR}/$OUT_FILE` fi if ;then exit_proc "Word_count is more than allowed limit" 1 else... (6 Replies)
Discussion started by: Sri3001
6 Replies

2. Shell Programming and Scripting

Integer expression expected

Hi, I am getting the below error while comparing the month of a file to current month. I am using ls -lrth to get the month of that file and while using the if else condition i am getting the below error.. a1=`ls -lrth abc.txt | awk '{print substr($6,1,3)}'` This gives me the month from... (1 Reply)
Discussion started by: jaituteja
1 Replies

3. Shell Programming and Scripting

Integer expression expected

I need some help with this if but then it says line 11: I don't know what I'm doing wrong (1 Reply)
Discussion started by: margg
1 Replies

4. Shell Programming and Scripting

Integer expression expected

Hi, I have placed the script and running successfully on AIX However in Linux it throws integer expression expected Could some one please help me to fix this MaxThreshold4alert=`echo "$MaxCapacitycnt*(80/100)" |bc -l` echo $MaxThreshold4alert Error: 40.00000000000000000000: integer... (2 Replies)
Discussion started by: ajothi
2 Replies

5. Shell Programming and Scripting

Integer expression expected

hi Guys, when i run the below script its showing error "integer expression expected" script pasted below: #!/bin/sh for i in {1..$2} do if then scp server1:/root/file.2012-$1-0$i . else scp server1:/root/file.2012-$1-$i . fi done (8 Replies)
Discussion started by: ganga39
8 Replies

6. Shell Programming and Scripting

Integer expression expected

Newb here echo "$yesterdaysclose" echo "$close" if ; then echo "stocks moving up" elif ; then echo "stock is moving down" else echo "no change" fi seems to evaluate the floating decimal correctly however returns ./shellscript1.sh: line 17: [: : integer expression expected... (3 Replies)
Discussion started by: harte
3 Replies

7. UNIX for Dummies Questions & Answers

Integer Expression Expected!?!?

Ok, so I am beggining a script to factor the time difference from when a user logs on to current time but before I can even get too far I am getting the INTEGER EXPRESSION EXPECTED error. Can someone tell me what I am doing wrong? lhour=$(who | grep "$1" | cut -c30,31); lmin=$(who | grep "$1"... (1 Reply)
Discussion started by: losingit
1 Replies

8. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

9. Shell Programming and Scripting

:integer expression expected

Hi, echo $i until || do read NUM if && ; then printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG" fi done Getting below error : ./import_location.sh: line 234: [: : integer expression expected ./import_location.sh: line 234: [: :... (5 Replies)
Discussion started by: milink
5 Replies

10. Shell Programming and Scripting

Integer Expression Expected

Cannot figure out what the error is on line #10 I was trying to change my login prompt though I've success with that this shows up as well. Here's what I have (1 Reply)
Discussion started by: moonunit
1 Replies
Login or Register to Ask a Question