about "eof"
I'm reading a book about linux and I saw a line of bash command goes like that
cat > catfile << "eof" Well, the book say that, If I type "eof" after what I wanna input in catfile, the input is down, but I have no idea what the "eof" in the bash cmd did? As a input file? I dont think so. Are there any config file can give me any clue what exactly happened, any help is appreciated. |
The 'eof' part harkens back to End Of File, but in the case you are looking at it can actually be any word and it is creating a Here Document (more here) and it simply tells
where the input to the document ends |
the << means stdin input, not from a file. here this common, and pretty weird looking, command means to take the stdin stream until it sees the string "eof". When it sees that, it will stop writing to the file (and not include that string in the file. It's a nifty way to write files out from a script file....
Code:
cat > catfile << "eof" |
re:grail
Quote:
|
Its same as pressing CTRL + D in interactive mode.
Code:
cat > catfile For example: PHP Code:
|
Quote:
|
yes, it can be any string, just make sure there's no way it could appear sooner in the body of text. "_EOF_" is the most common string I'd say.
|
As a side note, I also like to use the here document to comment out portions of code while testing:
Code:
echo testing new feature |
All times are GMT -5. The time now is 05:25 PM. |