/usr/local/bin/expr function not working

Legends,

I am not able to set "expr" function in ksh script.
Below is the sample code i used, and output is as "Syntax error"
Please help me to come out of it.

OUTPUT

what is there in /tmp/loadDSdata.tmpl ?

---------- Post updated at 02:53 PM ---------- Previous update was at 02:48 PM ----------

if the BASENAME is numeric then you can try the below

 
len=$((${#BASENAME}+2))
len=$((${#len}+7))
cutoffdate=`/usr/local/bin/expr $CurrentDate - 3`

You can't do date arithmetic with expr.

What OS your using..? Maybe you can try as Len=`/usr/local/bin/expr "$BASENAME" : '.*'` instead of length expression.

1 Like

$BASENAME is not numeric..its say "India"

@Franklin52, but i am getting value in cutoffdate variable

@itkamaraj; in /tmp/loadDSdata.tmpl i have contents like below
Kenya
India

Then it will go to directory search for Kenya_*.csv file and remove.

---------- Post updated at 01:43 AM ---------- Previous update was at 01:42 AM ----------

@michaelrozar17

Thanks dear, that worked.

---------- Post updated at 01:44 AM ---------- Previous update was at 01:43 AM ----------

IT WORKED :slight_smile:

And what should be the result if you subtract 3 from a date like 20120101?

20120101 - 3

Right... so it will fail every year for 1st 3 days...?

do you have gnu date ?

check the below command works in your system.

 
date -d "yesterday"

And let us know, what is your OS

More like every month the first three days...
Have a look at this thread where Perderabo lists some possible ways to solve date arithmetic problems.

@itkamaraj; its SunOS