The difference between `command` and $(command)

The old style backticks ` ` and the $( ) constructions do the same thing, but treat the backslashes different.

Watch Free Movies

Using backticks:

$ echo `echo test`
test

Using $( ):

$ echo $(echo test)
test

In the $( ) construction, everything in between ( ) is interpreted as a command.

As we can notice, the two tricks behave different when interpreting special characters:

With $( ):
$ echo $(echo '\\')
\\

With backticks:
echo `echo '\\'`
\

In the second construction, the “backslash” \ escapes the second one, while in the first, the sell interprets it as normal character an prints two “backslashes” \\ .

I avoid using the backticks, because they can easily be confused with the normal ticks ‘ ‘.

All the new shells support both the ` ` and %( ) constructions. The old bash does not know how to interpret the $( ) trick.

Scroll to Top