What’s the difference between $(…) and `…` in Bash

bash

I got expected result with `…`, but failed with $(…)

kill $(ps ux | grep S..\.tcl | grep -v grep | awk '{print $2}')

Illegal variable name.

kill `ps ux | grep S..\.tcl | grep -v grep | awk '{print $2}'`

(kill expected processes)

By googling, I found some says they are interchangable, but it is not by this example. So, What's the difference between $(…) and `…` in Bash?

Best Answer

I did a

grep -al 'Illegal variable name' /bin/*

and found the message in /bin/csh. Looks like you are running csh not bash when you are giving the command. eg:

csh $ echo `echo abc`
abc
csh $ echo $(echo abc)
Illegal variable name.
Related Question