I'd like to know what's the difference between these two commands:

echo ` echo `date` `

echo ` echo \`date\` `

I know that \ is used to escape characters, but I cannot understand it in this particular context. Why aren't we using

echo \` echo \`date\` \` 

instead, if we are supposed to escape ` character?

1 Answer 1


You can use the other expression for backquotes $(cmd), that can be nested. On the other hand, you can produce inner arguments to backquotes into variables and use them inside

echo $(echo `date`)
echo $(echo $(date))

x=`date` echo `echo $x`

Without the escape quote \`, you will have

echo $(echo )date$( )

The shell will try to parse the arguments, so try to figure the arguments of your expression, i.e.:

echo \` echo \`date\` \` 
argv[0]="echo", argv[1]="`", argv[2]="echo", argv[3]="`date`", argv[4]="`"

I leave the other examples to figure out for yourself.

  • Thank you for your response. I know the dollar sign notation used for nesting shells, and yes, I think it's much easier to use it instead of backquotes. Nonetheless, I still don't know, why do I have to escape those quotes inside second echo. I don't fully understand this mechanism probably.
    – threaz
    Commented Jun 21, 2015 at 14:38
  • @threaz that's simple: You start your Backquote command with ` and stop it with another `. If you don't quote the inner quotes the first inner backquote will be interpreted as the stop for the first backquote
    – ikrabbe
    Commented Jun 21, 2015 at 14:41
  • Ohh, I haven't thought about that. Now it's pretty simple. Thank you very much!
    – threaz
    Commented Jun 21, 2015 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .