Appending timestamp to a file. Why do I need this space ?

Version Info
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
$
$ echo $0
-ksh

I was trying to append date to the file name. The following syntax has worked

 
$ touch HELLO-`date '+%d-%b-%Y'`.txt
$ ls -alrt HELL*
-rw-r--r-- 1 rlapp  oinstall 0 Feb 20 10:28 HELLO-20-Feb-2013.txt
$

There should be a space after the date keyword. Without the space you'll get the following error

 
## Testing without the space after date keyword
$
$ touch HELLO2-`date'+%d-%b-%Y'`.txt
-ksh: date+%d-%b-%Y: not found [No such file or directory]
 

Why do I need this space after the date keyword ?

Without the space you are trying to execute a command named date+%d-%b-%Y instead of executing a command named date with the operand +%d-%b-%Y that tells date the format in which you want the date printed.

1 Like

date is a command like any other command, and therefore needs a space behind it if you provide arguments (in this case '+%d-%b-%Y')

1 Like