Quote:
Originally Posted by bucovaina78
I'm guessing it's all in the redirection of in/output.
|
Well... yes!
The sole purpose of cat is (according to the man page):
Quote:
cat - concatenate files and print on the standard output
|
So, as an experiment, try running "cat" alone on the command line. You'll see that it echoes everything you type as soon as you press enter. You repeat the process until you press Control-D (which sends an "end-of-file" character).
Just like any other command, if you use output redirection (the '>'), your shell will take the standard output of the command and write it to a file instead of displaying it on a screen. So, it's the
shell (e.g. bash, ksh, tcsh, etc.) that creates the file--not the cat command.
Similarly, the input redirection basically says "pretend that the text after '<<' indicates the end of the input".
Putting them together, the cat command is behaving exactly as though it were given no arguments. Your shell is the one moving data around. As you type, the shell is looking for "EOF" to signal the end of the input. When that text is seen, it sends cat an end-of-file signal so that cat stops processing things. Also, cat is echoing everything you type as before, except that as it's echo'd, your shell is grabbing that text and writing it to a file--so you never see it displayed.