-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
  • 7,055
  • 20
  • 53
  • 94

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,418
  • 1
  • 10
  • 28