user1801934 user1801934 - 6 months ago 17
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

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

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