Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Setting Date Variable for Cron Job



>>>>> "Charles" == Charles Muller <acmuller@example.com> writes:

cp -f /home/chuck/.emacs /home/chuck/Documents/programming/emacs-`date+"%Y%m%d"`.txt

(1) As a matter of style, you should put the `+' inside the "".
(2) You don't need the "".
(3) You _do_ need a space between the "data" and the "+" -- it's
    protected by the backquotes, so it doesn't break up the file name.
(4) You should get in the habit of doing this in stages, eg

TIMESTAMP=`date+"%Y%m%d"`
cp -f /home/chuck/.emacs /home/chuck/Documents/programming/emacs-$TIMESTAMP.txt

The reason is that as you start doing more complex things, you'll want
to manipulate the same file later, eg

TIMESTAMP=`date+"%Y%m%d"`
cp -f /home/chuck/.emacs /home/chuck/Documents/programming/emacs-$TIMESTAMP.txt
gzip -9 /home/chuck/Documents/programming/emacs-$TIMESTAMP.txt

There are ways to do this without the variable, but they're either
less reliable, or harder to understand and debug.

-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
 My nostalgia for Icon makes me forget about any of the bad things.  I don't
have much nostalgia for Perl, so its faults I remember.  Scott Gilbert c.l.py


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links