user1801934 user1801934 - 1 year ago 82
Bash Question

date -d option usage in Shell Scripting

date -d '($VAR) hours ago' +"%Y-%m-%d %H"

This gives me the wrong result. How do I pass in the variable in date -d option?

Answer Source

Variables won't be expanded when put inside single quotes, use double quotes instead:

date -d "$VAR hours ago" +"%Y-%m-%d %H"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download