Not able to manipulate date on Unix shell script (

2019-07-17 09:10发布

I have a requirement to add 10 days to current date and assign it to a variable. But I am getting error:

date: illegal option -- d

This is what I tried:

$> NEW_expration_DATE=$(date -d "+10 days")

Result:

date: illegal option -- d
Usage: date [-u] [+Field Descriptors]

2条回答
手持菜刀,她持情操
2楼-- · 2019-07-17 09:22

Try this: NEW_expration_DATE=$(gdate -d "+10 days")

查看更多
成全新的幸福
3楼-- · 2019-07-17 09:33

It looks like you are using a POSIX shell, and that there is no way to do simple date arithmetic in here.

I found a guy who explains it and who coded something to substract dates. You may be able to adapt it for your case: https://unix.stackexchange.com/a/7220/162444

Good luck!

查看更多
登录 后发表回答