Ludovic S
Ludovic S

Reputation: 195

Put result of command in a environment variable

I would like to put the result of the command date +"%Y.%m.%d" -d "yesterday" in an environment variable.

I tried export YESTERDAY_DATE=date +"%Y.%m.%d" -d "yesterday" but got an error stating the identifier is not correst.

How could I do it?

Upvotes: 0

Views: 79

Answers (2)

Ricola
Ricola

Reputation: 43

Alternatively, you can use this syntax:

YESTERDAY_DATE=$(date +"%Y.%m.%d" -d "yesterday")

See also here:

What's the difference between $(command) and `command` in shell programming?

Edit: Missing the capability of commenting the above solution: That's exactly why I prefer $() over ` - it's copy/pasteable (some systems have problems with backticks ...)

Upvotes: 3

flafoux
flafoux

Reputation: 2110

export YESTERDAY_DATE=`date +"%Y.%m.%d" -d "yesterday"`

Upvotes: 3

Related Questions