I’m trying to check whether a particular service is running via a Linux terminal, and the following command doesn’t seem to be filtering the results as expected. Not sure what I’m doing wrong…
service --status-all | grep subversion
This produces several lines of output, including, for example,
[ ? ] Networking
I’m not sure why this is happening, since the string “subversion” is not contained within the above line…
Advertisement
Answer
You should use:
service --status-all |& grep subversion
Because the services without a status ([ ? ]
) are sent to stderr, which is not pipelined to grep (and then it is printed on your terminal regardless).
|&
sends stderr to stdout so grep is able to filter it.