I'm trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to it. Is it right?

cat << EOF >> $log 2>&1   
the quick brown  
fox jumps  
  • 2
    Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use. – ctrl-alt-delor Aug 30 '14 at 16:11
  • it does the same thing every cat statement does - it concatenates stdin to stdout. – mikeserv Aug 30 '14 at 17:58
  • The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work. – Anko Aug 30 '14 at 23:34

First, cat must be written lowercase. This command statement uses the concept of here documents.

The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:

This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (in your case it's EOF) (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.

The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.

Conclusion: A file like this is now generated:

the quick brown
fox jumps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.