Retreiving and storing date...

First of all want to apologize for such a simple question. Very "new" to UNIX and have just taken a small intro class.

I need to pull back YYYYMMDD and store it in a field to be used later. I figured out date "+%Y%m%d" returns the date in that format, just not sure how to store it.
I am going to be emailing a file that is called for example report20090303.txt.

touch report`date "+%Y%m%d"`.txt

touch `date 'report+%Y%m%d'`.txt

Don't really understand what the "touch" does. I thought this would work, but it isn't...

Store the Date as follows:

DATE=$(date +%Y%m%d)

Then email it like this...
cat '${report_file}$DATE.txt' >> mailfile
echo "
--^A^A^A^A^A--" >> mailfile

sendmail ${recip_adr} < mailfile

I am getting the following error though:
Cannot open ${report_file}$DATE.txt. Why is it not resolving the symbolics?

the touch command create an empty file.

try it like that:

DATE=`date +%Y%m%d`

Then email it like this...
cat ${report_file}${DATE}.txt >> mailfile
echo "
--^A^A^A^A^A--" >> mailfile

sendmail ${recip_adr} < mailfile

Thanks, I am getting closer...

      now it is putting 'date \+%Y%m%d' in \{DATE\}, not the value 20090303.

Make sure you have a backtick (`) not a single quote ('). Its doesnt have the same effect.

You should have that :

DATE=`date +%Y%m%d`

and not :

DATE='date +%Y%m%d'

Wow, this is picky! :slight_smile: That worked, thanks for your help!