I learn that pipe (|) is used to pass stdout into subshell's stdin.But, command less must have filename argument like less file1.txtHowever, when I use command like ls -l /root | less, it works.So, I assumed that in this case, less takes stdin file which is written from ls -l /root's stdout. I mean, in real, less stdin when less do its own command. But, because of another command, I got confused. It's tr command.tr command doesn't take any file argument like tr a-z A-Z file1.txt. It just take stdin from keyboard or redirected stdin. But, command ls -l /root | tr a-z A-Z is possible. Then, what I assumed is wrong.How pipe works in real? The basic is that pipe passes main shell's standard output into subshell's standard input. But, I can't know main shell's standard output goes to subshell's standard input file or just it takes situation that I enter the characters from keyboard. But, when I see above examples, shell takes both situations.
less command with pipe
shell;pipe;command
So, I assumed that in this case, less takes stdin file which is written from ls -l /root's stdout.This is correct, and it doesn't contradict what you observed with tr.The shell's pipeline construct (PRODUCER | CONSUMER) creates an anonymous pipe before starting the two processes PRODUCER and CONSUMER. An anonymous pipe is a type of file that doesn't have a name, it doesn't have a directory entry, but it can be read and written normally. In a pipeline, the shell connects the write end of the pipe to the producer's stdout and the read end of the pipe to the consumer's stdin.The tr command only ever reads data from stdin and writes to stdout. The less command does this only if you don't pass it a file name on the command line; if you pass a file name to less, it reads from this file instead of reading from stdin. What less does is a common convention, followed by many similar applications that read data from one file.You may also be interested in what is meant by connecting STDOUT and STDIN? and How can a command have more than one output?