Can anyone explain when and how to use << operator for input redirection? I've googled enough but couldn't find.
Asked
Active
Viewed 587 times
3
2 Answers
5
The <<
redirection operator introduces a "here document": the text fed into standard input comes just after the redirection.
Here's an example:
grep Hello <<EOF
This line won't appear
Hello this one will
Hello again
EOF
All the text between <<EOF
and EOF
is fed into grep
. EOF
isn't special here, the shell takes the word given just after <<
and uses it as a delimiter.
An interesting variant is <<-
which strips leading tabs.
See the bash
documentation for details.

Stephen Kitt
- 434,908
3
This operator is used for multiline redirect. See below for example
program <<KEYWORD
line1
line2
line3
KEYWORD
The above send line1, line2, line3 strings, delimited with newline
You should not have KEYWORD (can be any other word) in the text. And last line with KEYWORD should start from begin, no space, no tab, etc

Romeo Ninov
- 17,484
man
command? – Stéphane Chazelas Apr 22 '15 at 10:06