Both
echo `date`
and
echo "`date`"
will display the date. The output from the latter looks like the output from running date
by itself.
There's a difference, though: the one surrounded in "
quotes "
will be sent to to echo
as a single argument. The quotes encapsulate the output of the entire command as one argument. Since echo
just prints out its arguments in order, with spaces in between, it will basically look the same.
Here's an example of the subtle difference:
echo `date`
produces:
Fri Nov 1 01:48:45 EST 2013
but:
echo "`date`"
produces:
Fri Nov 1 01:48:49 EST 2013
Note that the two spaces after Nov
were reduced to one without the quotes. This is because the shell is parsing each space-separated element and sending the result to echo as 6 arguments. When you quote it, echo receives one single argument and the quotes retain the space.
This becomes much more important in commands other than echo. For example, imagine a command foo
that wants two arguments: a date, and an email address.
This will work in that scenario:
foo "`date`" [email protected]
But this will confuse the script by sending it 7 arguments:
foo `date` [email protected]