0

The following command issued from a terminal gets me yesterday's date:

date --date='1 day ago' +%Y/%m/%d 

I'm trying to write a bash script where the number of days is a command line arg. I'd like to be able to store the resulting date in another variable and use it later in my script. Thoughts?

1 Answer 1

2
 x=$(date --date "$1 days ago" +%Y/%m/%d) 

Where $1 is the first command line argument. Make sure you use double-quotes instead of single quotes, other wise the argument isn't expaneded.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.