Does cat never read from terminal

catio-redirectionstdin

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command:

Standard input (stdin) normally comes from your keyboard. Many
programs ignore stdin; you name files directly on their command line —
for instance, the command cat file1 file2 never reads its standard
input; it reads the files directly. But without filenames on the
command line, Unix commands that need input will usually read stdin.
Standard input normally comes from your keyboard, but the shell can
redirect stdin from a file.

(emphasis mine)

Ok but happens when we just type cat > filename in the command line? Isn't cat reading from the stdin and stores that that into file "filename"? Is the above excerpt from the book just saying that only the particular form of using cat with a FILE argument never reads from the stdin?

Best Answer

Isn't cat reading from the stdin and stores that that into file "filename"?

Yes, when cat does not have any filename arguments (or if one of the files is the minus character -), it reads from stdin.

Perhaps use of the word "never" by the book is a bit misleading, because:

Is the above excerpt from the book just saying that only the particular form of using cat with a FILE argument never reads from the stdin?

Yes, in that particular instance, cat will not touch stdin.

Related Question