tags:

views:

115

answers:

3

When "cat > xx.txt << EOF" is entered on the command line, further input from cmdline goes to file xx.txt until EOF is written. EOF is not a sacred word here, if instead the command was cat > xx.txt << BBB, then cmdline input goes to xx.txt until BBB is written. I don't know whats the rationale behind ( << end_of_input_sequence)this. Cat man page does not explain much. I have only seen this in scripts etc.

+7  A: 

It's a feature of the shell, not cat - that's why you won't find it in the cat manual.

It's known as a "Here document" - see this page of the Advanced Bash-Scripting Guide for some documentation.

RichieHindle
+6  A: 

This is called a here document. I believe it first appeared in shells, but some programming languages such as Perl, Ruby, and PHP also implement this style.

Greg Hewgill
+3  A: 

Hi,

This syntax is called Here Document (scroll a bit to find it).

It's not specific to any command, not cat anymore than any other command ; and it can be find in the man of the shell ; for instance, man bash :

3.6.6 Here Documents

This type of redirection instructs the shell to read input from the current source until a line containing only word (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.

(Not a full quote -- there is more to read in the man)


BTW, It's a syntax that has been re-used in some programming languages, like PHP ;-)

Pascal MARTIN