simply takes all the input given to it from sdtin
or a list of files, and prints it to stdout
. This has the effect of "concat
enating" all input into one continuous stream.
It's traditional uses are to combine multiple files into one (hence the name), as a quick way to print out the contents of a file for reading, and to redirect user input into files or commands, as grail demonstrated. One thing you should generally not
use it for, however, is to feed the contents of a single file into another command (the Useless Use Of Cat
). Just use the shell's "<
" redirection for that, if the command in question can't read files directly.
There are also a handful of useful input filtering options built into it. cat -A
will display all non-printing characters, for example, and cat -n
will prefix the output with line numbers.
In the OP code, cat
wasn't given any files to read, or any scripted form of stdin
input (such as the heredocs demonstrated above), so it just sat there listening to stdin
for something to print. If you had typed something into the shell then cat would have printed it to stdout
(redirected to the file in this case), and continued doing so until it received an EOF (end-of-file) signal or was otherwise externally terminated.