Your date
command prints an extra space before the day-of-month if the day-of-month is a single digit.
Here's your first command:
echo $(date)
Since you didn't put double-quotes around $(date)
, the shell performs word-splitting on the output of date
, and passes each word as a separate argument to echo
. In word-splitting, the shell considers two consecutive spaces to mean the same thing as a single space. So the shell “eats” the extra space emitted by date
.
Here's your second version:
echo "$(date)"
Since you put double-quotes around $(date)
, the shell does not perform word-splitting on the output of date
. It passes the entire output of date
, except for trailing newlines, as a single argument to echo
. So the shell preserves the extra space that was output by date
.