cat > $FILE_NAME << EOF - Explanation of the inner workings

0

I know what this one does, I learned "pattern like" and just works.

I also know:

  • that > is a redirect to a file
  • that << is also a redirect to file see below
  • EOF is just a placeholder, when detected the file is closed

Can someone explain the inner workings of those instructions? Why does that work ?

Correction: the use of ´<<` is described in the man page of bash as:

<<[-]word
    here-document
delimiter

So it is the current source that is read from, which I think is stdin. Could someone decompose this into smaller chunks, that I can understand?

I think delimiter corresponds to EOF in my example, right?

And here-document is probably the text I type in in stdin, right?

I fail to see what is word.

Ely

Posted 2015-05-17T23:43:55.367

Reputation: 150

1<< is not a redirect from a file. <<EOF signifies the start of a here document. Open man bash and go to the section entitled "Here Documents." – John1024 – 2015-05-18T00:31:53.110

1

There are many, many references on how to use the shell on the Internet (and some of them are clear and accurate).  Start by reading the very next paragraph of bash(1) after the block you quoted; also check What are the shell's control and redirection operators? (here on Stack Exchange).  Please do some research on your own, and let us know if something specific is hard to understand.

– Scott – 2015-05-18T01:43:42.977

Your link is perfect. The use of two different identifiers "word" and "delimiter" was confusing, they are actually the same. Thanks. – Ely – 2015-05-18T01:50:39.880

No answers