0

While looking for how to filter command in top console, I found the answer.

top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)

It works perfectly.

I think It is the same as the command pgrep -d ',' -f cmdStr | top -c -p because they will work to feed the output of pgrep to input of top at least I think.

However, as you expect it returns an error top: -p requires argument

What is different between them?

asleea
  • 237

1 Answers1

3

No they are not the same. Consider the echo command. Do you expect

echo hello asleea

and

printf "asleaa\n" | echo hello

to produce the same thing? In the top ... $(...) case the shell first runs the stuff inside the $(...), and places the output in the list of arguments for when it runs top.

Of course top could be written to read additional values from stdin if you gave it a flag which required an argument but didn't give it one, but that is not how it is implemented.

icarus
  • 17,920