0

What happens when the following command is executed? Explain why, and how to fix it:

$ echo ‘`date`’
  • 2
    Did you mean to use curly quotes? What behaviour are you expecting? – Stephen Kitt Apr 7 '17 at 16:38
  • 2
    Why don't you tell us what happened? You're the one who ran the command, after all. What did you see? What were you expecting to see instead? – terdon Apr 7 '17 at 16:55
6

I’m guessing you’re running

echo '`date`'

(note the straight single quotes) and expecting to see date’s output. The shell never expands strings inside single quotes; you should use double quotes instead:

echo "`date`"

or just drop them

echo `date`

All this is equivalent to

date

though, apart from the shell splitting and globbing (as pointed out by Stéphane Chazelas), which will collapse blanks by default.

  • Strictly speaking, echo `date` is not the same as date. The former means calling the split+glob operator on the output of date. With the default value of $IFS, that will squeeze sequences of blanks into one space. See also with export TZ='***0' on some systems. – Stéphane Chazelas Apr 7 '17 at 16:55
1

As posted, the outer quotes are Unicode U+2018 and U+2019 characters. These are NOT regular single quotes and have no special meaning to shell and are simply echoed:

$ echo ‘`date`’
‘Fri Apr 7 19:55:15 EEST 2017’
$ 

Inside these quotes are backticks for shell command substitution. The date command is executed and the captured output replaces the date string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.