I have a process that I want to kill remotely. I tried
ssh remotehost "kill -9 $(ps -aux | grep foo | grep bar | awk '{print $2}')"
but this returns the error
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
However if I run the command within the quotation marks
kill -9 $(ps -aux | grep foo | grep bar | awk '{print $2}')
on the remote host it works fine. Am I missing something here?