Pipe symbol for Linux "|" I have always had a doubt that when I want to use a command similar to the following, I always do not achieve the result I want:
Suppose there is a file: Path.txt
An address was recorded inside:
Cat path.txt~/download/
And I want to get this address through the "|" Import into a CD or LS command, such as this:
Cat Path.txt | Ls
But it is not always possible, it does not list the contents of ~/download.
I went through some inquiries and found something.
We usually give LS after the string of things is a parameter, and pipe character passed to LS only the standard input, LS is not from the standard input parameters.
grep can receive standard input, so it works correctly like LS | grep log.tx T's command,
So what's the difference between grep and LS?
This needs to distinguish between two things: 1. Parameters 2. Input
The operation of the command requires that we assign some parameters to it so that it knows how it should work in order to satisfy us.
ls -alPS -EFrm -RF
-AL-EF-RF are arguments to the command that tell the command how they should complete the task.
For LS | In the case of grep Log.txt, Log.txt is the parameter of grep, and the argument cannot be by the pipe character "|" Provided by the standard input given.
grep from the pipe symbol "|" Where did you get the stuff?
The answer is that the standard input of the pipe character enters the buffer, waiting for grep to read like the scanf () function.
We can do an experiment where we type in the terminal
grep 123
We will find the program is interrupted, it seems to be waiting for what we enter, so enter 12345,
The result program outputs 12345,
We'll enter 67890,
The program does not have output, it seems that the reason is very obvious, the standard input pipe character came here, was grep like scanf () function read.
Mommy never had to worry about my cat Path.txt | LS Why can't it run?
Because LS requires parameters, not the standard input that will run into the buffer!!!
Questions about piping characters in Linux