6

I would like to create an environment variable that will output the current date. I have added the following to ~/.pam_environment:

TODAY=$(date +%F)

Apparently, you have to log out after changing ~/.pam_environment. I did that but

echo $TODAY

outputs a blank line.

What am I doing wrong?

3 Answers 3

5

~/.pam_environment is not a script file. Use ~/.profile instead:

export TODAY=$(date +%F)
2

You forgot the "quotes" Here is a Cool Link for more examples.

TODAY= date +"%F"
2
  • Unfortunately that did not work. I tried experimenting a bit and added the following to ~/.pam_environment: TODAY=date +"%F" TODAYS=$(date +"%F") NOW=$(date +"%m-%d-%Y") None of these are working Apr 25, 2013 at 1:32
  • 2
    @ScottGoodgame That's not the problem. It is not generally necessary to quote %, and although the reference you provided follows this style, it does not actually say one has to do so. Try some examples from that page without quotes (e.g., date +%m-%d-%y). It works fine. In addition, TODAY= date +"%F" actually runs date +"%F" with TODAY set to the empty string in its environment. Jan 25, 2017 at 11:23
0
$ export DATE=`date +"%F"`
$ echo $DATE
2014-05-30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .