Not able to manipulate date on Unix shell script (date: illegal option — d)

坚强是说给别人听的谎言 提交于 2019-12-12 21:27:32

问题


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]

回答1:


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




回答2:


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!



来源:https://stackoverflow.com/questions/36631711/not-able-to-manipulate-date-on-unix-shell-script-date-illegal-option-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!