0

I have the following command:

wash -n <groups> <<EOF
echo hi 
echo bye <<BYE

<commands>

exit 0
BYE
exit 0
EOF

<commands>

where <groups> are some groups and <commands> are commands. I don't understand what <<EOF and <<BYE mean? Is it some label which the script jumps in case fails? What does this script do?

2
  • It is called a "here" document. It allows you to add stdin alongside the command in a script.
    – unxnut
    Apr 5 at 16:11
  • See also the here-document tag.
    – Kusalananda
    Apr 5 at 16:57
2

It is a feature named "here document". Basically it means that the text between <<whatever and whatever are presented to the standard input of the command. In your case, the stdin seen by the first command is,

echo hi 
echo bye <<BYE

<commands>

exit 0
BYE
exit 0
2
  • So if <commands> is echo inside, I get hi and the bye. It does not run the command echo inside. Not sure I understood the flow.
    – vesii
    Apr 5 at 16:41
  • @vesii The here-document does not matter much in this example as echo does not read from its standard input stream. The contents of the here-document is simply discarded.
    – Kusalananda
    Apr 5 at 16:55
-1

tl;dr: command << TEXT: the string TEXT is treated as end-of-file.

I tested, and it seems to be like this: When you do:

% command << TEXT

csh reads the standard input, and when it catches TEXT, the full stdin before TEXT is redirected to command. (TEXT has to be on a separate row to work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.