Shell Including date in filename

I was looking for a way of including the date in a filename and can across this answer. So I tried touch "$(date +"%Y_%m_%d_%I_%M_%p").log" and touch $(date +"%Y_%m_%d_%I_%M_%p").log and both returned:-
Illegal variable name.
How can I do this under FreeBSD?
 
I figured it out eventually, after a bit of trial and error, slightly different... ie without quotes (")

touch todays-$(date +"%m_%d_%Y").log

Just noticed my paste didn't work properly... should have been:-
touch todays-[ICODE]date +"%m_%d_%Y"[/ICODE].log

Hmmm.... seems like embedding the command in a CMD tag strips of the backticks... Here it is as a CODE fragment:-

Code:
touch todays-`date +"%m_%d_%Y"`.log2
 
Use echo $(date) instead of
Code:
echo `date`
.

Edit: Annoying, the forum software automatically translates backticks to an [icode] block, even if you enclose it in [noparse]. Another reason not to use backticks.
 
Back
Top