Вопрос

I have a unix script where I get the following arguments from command line:

startDate=$1
endDate=$2

I want to check both dates whether they are in yyyyMMdd format or not? How can I do that? If the format is incorrect, I want to exit the program.

I am running a java spring batch program in the same script as below:

java commandLineJobRunner jobConfig.xml myJob currDate=$currDate

Basically I am passing a job parameter viz. currDate to myJob spring batch job.

I want to loop above program such that the program should run for all dates between startDate and endDate that is for currDate=startDate to currDate=endDate with currDate incrementing by a day in each loop.

How can I achieve this ?

Это было полезно?

Решение

In BASH/ksh for basic validation of startDate in yyyMMDD you can use:

[[ "$startDate" == [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]] && echo "valid"

To get next day from $startDate you can use:

nextDay=`date '+%Y%m%d' -d "$startDate next day"`
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top