For 2 days old date I usually do this

echo $(date -v -2d)

What i am looking to do is something like this

echo $(date -v -nd)

1 Answer 1


Solved it myself

echo $(date -v -${n}d)
  • 5
    Why the echo? date -v "-${n}d" should be enough. Sep 25, 2019 at 12:24
  • sure point noted, but why quotes? it works without it as well. Sep 25, 2019 at 13:11
  • 2
    See Security implications of forgetting to quote a variable in bash/POSIX shells Leaving it unquoted introduces an unnecessary dependency of that code on the $IFS variable in shells like sh/bash Sep 25, 2019 at 13:53
  • 3
    BTW, don't be put off by downvoters. You did the right thing to post an answer to your own question after you found it yourself. Note that it's perfectly fine to edit your posts to merge in suggestions given in comments by others. What matters is that in the end we have the most helpful Q's & A's as possible. Sep 25, 2019 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.