You are correct that |
feeds the output of one program to another. The data flows left
to right
. So you might think that
pgrep dnsspoof | kill
should work, as pgrep
will find the process number of dnsspoof and feed that to kill
, which would then kill it. It turns out that this doesn't work, as kill only looks at the command line to get the things to kill.
So we have to get the output of pgrep
onto the command line. This is what
`pgrep dnsspoof`
or the more modern $(pgrep dnsspoof)
does, it runs the command inside the backticks or brackets and puts the output in place of the command. So if pgrep dnsspoof
outputs 5432
, then the command that is then run is kill 5432
, which is the correct way to invoke the kill program.
Using $( )
has several advantages, easier nesting, less things need to be escaped, so if your shell supports them then you should use them in prefference to ` `
.
kill
as a command, all by itself, and look at its output. Now, what good do you think will come of piping that into another program?