Find the next day from 20100303 (YYYYMMDD format)

Hi ,
i have doubt in bash shell script..
for example my file name is sampledate.sh
given command = ./sampledate.sh -d 20100303 -f karthi
how to find the next day from 20100303 (YYYYMMDD format)
After getting the next day ,changed date and -f argument value will be sent to one java class.

waiting for your response
Thanks

If you want the next date you can use the following way

full_date=$2
date=${full_date:4:2}
let next_date=$date+1;
if [ $next_date -lt 9 ]
then
        next_date="0"$next_date #adding trailing zeroes
fi
echo $next_date;

Hai Thillai,Karthi has clearly mentioned the date format in his post itself.Did you read it fully before you answer?Thillai,I think your solution won't be correct.Because,if the day number is 30 or 31,what happens,check it out?In your case,it simply incremented by 1.Then,the day will be 32 or 31.Whether it is expected?

Hai vivek! Thanks for your feedbacks! Actually I pointed the sample way of getting the next date.
I have given the basic the ideas only.
We are not here to write code from A-Z for the user's complete requirement.
We need to give the basic ideas.
That basic idea should make the poster to think in writing the code.
Here lot of stuffs should be achieved.
We need to check the month values. Because alternate months will have the last dates as 31,30,31,30 etc.
And also For the feb month also we need to consider.
If the date count is reached the last date for the particular month we need to increment the month count.
If the month count is reached 12 then we need to increment the year count
And we need to consider the leap year's Feb days.
Lot of stuffs are there.
I pointed the basic things about extracting the next date from the given command line argument.
Have you got my point?

Yeah Thillai,nice of you.But,it is better to mention before which means in your first reply itself.

thanks for reply

You mentioned $2 for getting date right?
but run time if i give
./sampledate.sh -f karthi -d 20100303 means wat ll happen?

You need to change that as $2 to $4.

Actually $0 represents the first command line argument. This will be usually a script name. $1 will be next argument and so on....

Ok...
but given arguments may be unordered by such kind of users ,in that situation how can v handle?

You need to compare each and every argument by for loop and if condition.

You can get every thing about date in here...

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

As stated above, this FAQ will tell you what you need for more complex date and date arithmetic: http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

For this specific problem, you can just use the date command.

If you have the GNU version of date, just use:

date -d "yesterday" "+%Y%m%d"

If you have BSD, POSIX, Solaris version of date, here is a simple shell script that will do it.

#!/bin/bash

#call with (basename) 'YYYYMMDD' [+-deltadays]

#there is no error checking, use at your own use...

if [ ! -n "$1" ]
then
  echo "Usage: $(basename $0) YYYYMMDD [+-days]"
  exit $E_BADARGS
fi  

if [ ! -n "$2" ]
then
  	deltadays=-1
  else
	deltadays=$2
fi  


epoch=$(date -j -f "%Y%m%d" $1 "+%s")

(( deltadays *= 60*60*24 ))
(( epoch += deltadays )) 

newday=$(date -j -f "%s" $epoch "+%Y%m%d")

echo $newday

THANKS FOR REPLAY...AND I GOT SOME IDEA FOR MY REQUIREMENT>>>

i need one more help....

if i have a string like aaaaa,bbbbb,ccccc,aaaaa

How to to split the string and check howmany times aaaaa will be in that string?

Please, don't piggy-back on existing threads - open a new thread for a new subject!