Invalid arithmetic operator

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Invalid arithmetic operator
# 1  
Old 08-11-2013
Invalid arithmetic operator

Hi experts,

I'm facing trouble with the below bash script, any help is appreciated
if (( "${date1}" > "${l_date1}" ))

echo "success"

echo "nothing"

the variable date1 contains 08/06/2013 and l_date1 contains 10/08/2013

this small script to single out the error. Please advise.

 > 08/06/2013 ")syntax error: invalid arithmetic operator (error token is "

# 2  
Old 08-11-2013
Don't use parentheses; use [[ . . . ]] instead.
And, be aware that this will be a string compare, so 10/08/2013 is gt 09/08/2014...
This User Gave Thanks to RudiC For This Post:
# 3  
Old 08-11-2013
Thank you rudi

that did it. Thank you

---------- Post updated at 11:44 PM ---------- Previous update was at 11:39 PM ----------

HTML Code:
if [[ ...]] && [[ ...]]
elif [[...]] && [[..]]
else "sometext"
Will this work?

Also is there any other way to deal with date comparison?

Last edited by parpaa; 08-11-2013 at 03:16 PM.. Reason: more info
# 4  
Old 08-11-2013
Have spaces around the [[ and ]], use ; then and fi, and then it should fly...
# 5  
Old 08-11-2013
Thanks again

One last question,

Is there any way to deal with date "comparison"??
since this will be a string compare;
# 6  
Old 08-11-2013
Convert to "seconds since epoch" or use YYYY/MM/DD format.
# 7  
Old 08-11-2013
thank you

Perfect, Thank you soooo very much SmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Invalid arithmetic operator on string concatenation

Hello. LEAP_VERSION="4.2" export ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update-Non-Oss')Seems that the - is interpreted as a numeric... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

BC calculation for floating (invalid arithmetic operator )

Hi, I wish to compare the CPU LOAD 1 min with 5mins and 15mins. If 1 min's CPU LOAd spike 3% compare to 5 mins or 15 mins CPU Load, it is warning. If 1 min's CPU LOAd spike 5% compare to 5 mins or 15 mins CPU Load, it is critical. However I received following code error, I google it and... (10 Replies)
Discussion started by: alvintiow
10 Replies

3. Shell Programming and Scripting

checking variables + arithmetic operator help

i'm trying to make a script to simply add numbers together for example i have a file script file called add add 1 2 3 4 5 15 however i want the user to put at least 3 numbers so i did this if then echo "please enter more than two numbers" exit 1 fi but it's telling me i have... (3 Replies)
Discussion started by: el3ctr0nic47
3 Replies

4. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

5. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

6. Shell Programming and Scripting

Arithmetic on timestamps

Hi Friends, please advise on shell script to add two time stamps for example : a=12:32 b=12:00 c=a+b=00:32 please help me to find shell script to add to two time stamps, as i need to convert time from EST to GMT or SST to prepare status of jobs in unix and to specify estimated time to... (3 Replies)
Discussion started by: balireddy_77
3 Replies

7. UNIX for Dummies Questions & Answers

Arithmetic Operators

Hello, I have a list of 'inputs' and i want to convert those on the second list named 'Desired Outputs', but i don't know how to do it? Inputs Desired Outputs 1 2 94 4 276 8 369 10 464 12 ... (0 Replies)
Discussion started by: filda
0 Replies

8. Shell Programming and Scripting

arithmetic in tcsh

Yes I know tcsh sucks for scripting and arithmetic but I have to write a script for multiple users and they all use tcsh. I have this variable that I 'set' with but pulling numbers off of stings with set STUFF = `grep string file | awk command` Now I would like to add up the numbers that... (4 Replies)
Discussion started by: gobi
4 Replies

9. Shell Programming and Scripting

arithmetic in ksh

Helloo.. I am trying one very simple thing I could not find anything on google.. I have 2 integer variable..and I need to do ksh where $catch and $num are integer variable.. I tryed with this: printf "%0.2f" $final=$catch/$num but it does not work.. any help is... (12 Replies)
Discussion started by: amon
12 Replies

10. UNIX for Advanced & Expert Users

time arithmetic

Can anyone help please. I am writing a kourne shell script and I am unsure how to do the following: I have extracted a time string from a logfile, and I have another time string I want to compare it to to see if it's later than the time I'm comparing with. i.e. expectedSLA="23:00:00", ... (2 Replies)
Discussion started by: csong2
2 Replies
Login or Register to Ask a Question