-1

I have a scenario where I need to calculate the date (yyyy-mm-dd) for X days from today's date in Linux. X is a user-input.

I tried the following:

X="-30"
date -d '$X day' '+%Y-%m-%d'

But this produces the following error:

date: invalid date ‘$X day’

How can I achieve this?

Thanks in advance!

activelearner
  • 6,105
  • 16
  • 47
  • 86

1 Answers1

-1

try this X="-30" date -d "$X day" '+%Y-%m-%d'

the $X variable won't expand in single quotes, which is the problem

Eby Jacob
  • 1,322
  • 1
  • 8
  • 26