2.3 Here Documents
2.3 Here Documents
...
In this example the shell takes the lines between <<! and ! as the standard input for grep. The string ! is arbitrary, the document being terminated by a line that consists of the string following <<.
Parameters are substituted in the document before it is made available to grep as illustrated by the following procedure called edg.
ed $3 <<% g/$1/s//$2/g w %
The call
edg string1 string2 file
and changes all occurrences of string1 in file to string2. Substitution can be prevented using \ to quote the special character $ as in
ed $3 <<+ 1,\$s/$1/$2/g w +
(This version of edg is equivalent to the first except that ed will print a ? if there are no occurrences of the string $1.) Substitution within a here document may be prevented entirely by quoting the terminating string, for example,
The document is presented without modification to grep. If parameter substitution is not required in a here document this latter form is more efficient.