using date in a variable name

Hi,
Another nubie to Unix programming.
I am using the Korne shell.
I am trying to use the system date as a name in a tar file. Here is the code to explain.

TODAY= date +%m%d%y
echo $TODAY ### it echo's 021606 which is fine

tar -cvf "$TODAY".tar *.std*

I think you get the idea.

What I get back is a file named .tar

I tried all kinds of configurations in the tar line and I can't get it to work.

It will not put in todays date for the name

I am looking for a file name 021606.tar

Am I way off or what.

Thanks, for the help in advance.

Phil

hmm, i tried exactly what you did, and I dont see any issue at all
does your tar command have any spaces or something in between?
is your stty erase set properly, i feel may be you typed backspace somewhere in your command
what is the shell you are using, not that it would matter, but what is it btw.

use backticks with the date command...

for example...

TODAY=`date +%m%d%y`

that should make a little difference. :slight_smile:

hmm that is not the case, coz ppopper says that the echo $TODAY shows fine, which means he has assigned today properly

Did it work when you tried my script?

I am using the ksh shell

Thanks

Phil

When I use back ticks I get a response from echo 021306 not found

is your stty erase set properly? I do not know what that is or how to check if it is set properly.

Thanks,

Phil

Hi I got this to work with tar -cvf `date %m%d%y`
I basically took out the variable assignment.
However it is a hidden file. I need to do an ls -f to see it. Any idea how to fix this?

Thanks,

Phil

that's weird.

the backtick is nothing more than the output from the commands executed in between them.

when i run:

today=`date +%m%d%y`
echo $today

i get '021306'.

that being the case... i changed it and did...

today="`date +%m%d%y`.tar"
tar -cvf $today ./ # tarring just the current dir tree to see if it works

...and everything worked fine... and tarred the files/dirs into 021306.tar

i don't know what kind of system you're using, but i've tried this on windows (Cygwin bash), Linux (Red Hat bash), and AIX (ksh) and got the same results.

don't know why it would be a hidden file. sorry... i wish i had more insight.

Hey Thanks Gents,
I was putting a space after the = in my variable definition. It works fine with out the space. I am use to using a debugger of some sort.

Thanks, again

Phil

ah yes, the infamous "space" char. i've accidentally done that MANY time. yes, a debugger would be nice, wouldn't it? you can, however, look into the "-x" flag with ksh which will pretty much show you all your vars, etc. as your script steps through each line.

The first line is the same as just
date +%m%d%y
and it produced the display that looked correct. Prepending "TODAY= " is legal to most commands and it temporarily set TODAY equal to nothing during the execution of the date command. This was a no-op since the date command does not use the value of TODAY. When we get the second line, we echo the current value of TODAY which apparently was nothing perhaps because the variable was otherwise unset. The OP saw the output from the first command and mistook is for the output from the second command. For debugging use statements like:
echo TODAY = $TODAY
to avoid this and other problems.