Skip to content
Advertisement

Piping To Grep Is Giving Too Many Results

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…

JavaScript

This produces several lines of output, including, for example,

JavaScript

I’m not sure why this is happening, since the string “subversion” is not contained within the above line…

Advertisement

Answer

You should use:

JavaScript

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement