What does this "... | ps `cat`" command do?
Solution 1:
xprop ... | sed ...
is executed first, then cat
reads its output. Due to the use of backticks, the output of cat is substituted in ps `cat`
such that the command becomes ps 1000
.
An alternative command that leads to the same result is:
ps $(xprop _NET_WM_PID | cut -d= -f2)
This works as follows:
-
Execute
xprop _NET_WM_PID
to retrieve the process ID of a window. After clicking a window, it outputs something like:_NET_WM_PID(CARDINAL) = 12345
- Split at the
=
and take the second field.cut -d= -f2
takes the_NET_WM_PID(CARDINAL) = 12345
string from standard input and writes12345
to standard output. - Finally run the
ps
command with$(...)
substituted for the output of...
, the command that gets executed isps 12345
. (side note:`...`
can also be used instead of$(...)
, though there are some differences)