Example: In a Terminal command
xdpyinfo | grep resolution(that I have taken from an answer), does the
|character mean that the
xdpyinfooutput shall be sent to the grep program input for printing a line containing the
resolutionstring? Where should I seek for such an information to avoid filling this forum by too simple questions? Thanks.
The vertical bar
|
is commonly referred to as a "pipe". It is used to pipe one command into another. That is, it directs the output from the first command into the input for the second command. So your explanation is quite accurate.It is called a
pipe
(or apipeline
) and it means that the output of the command in front of it are made as input to the command behind it.Example:
You are welcomed to try the command without the pipe.
And yes you are correct: in this case the command
xdpyinfo
shows information and it is parsed togrep
.grep
filters the results and only shows lines that haveresolution
in them.More information on
pipe
:The character
|
is sometimes called a pipe and is used to connect the output from one command and feed it into the other.So that
xdpyinfo | grep resolution
first runs the commandxdpyinfo
(a utility which displays information about X) without displaying any output. The output of this command is fed into grep (regular expression parser) to find any entries which contain resolution.What you see is just the info you want and not the complete output of the
xdpyinfo
command.Your interpretation is correct. The | character pipes the output of the first command into the input stream of the second. The two commands are actually running in parallel, as two concurrent processes. It is an illustration of the 'paradigm of pipes and filters' (building complex functions by pipelining simple ones), which is a hallmark of Unix.
For more information on this, I would suggest you follow through some tutorial on bash or shell scripting. There are plenty of those the web. I bet you will be surprised by the elegance and power of Unix/GNU shells.