Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm working on a bash script that backs up a configuration file before copying over a new file.

Here's what my snippet looks like:

mv ~/myStuff.conf  ~/myStuff.conf.bak
cp ~/new/myStuff.conf ~/myStuff.conf

Every time this script is run, I'd like there the backup to have a unix timestamp in the filename. I tried this

DATEVAR=date +%s
mv ~/myStuff.conf  ~/myStuff.conf.$DATEVAR.bak

But this doesn't work, since the date function doesn't execute and bash sees it as a string, and the resulting file ends up being

myStuff.conf.date+%s.bak

Any ideas on how to get the results of the date function into a variable?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This is possible with command substitution.

DATEVAR=$(date +%s)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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