Help to understand multi-line

This code

cat <<'EOF'
Red
Green
Blue
EOF

gives output to screen

Red
Green
Blue

Same output as

echo "Red"
echo "Green"
echo "Blue"

I do not understand why cat gives same output as echo
I do understand example above runs the command line by line until it find the tag EOF used as start from cat <<'EOF'

I am used to use cat as list output of file.

Also some more information on how multi line works. (a google for << does give nothing)

Try searching for "here document" instead.

Anyway, cat is reading from standard in (STDIN) and displaying the text line by line. Just like this:

$ echo hello | cat
hello
$

You are just telling cat to take STDIN a line at a time from the "here document".

For the fun of it, just type cat without any arguments and press enter. Now type something. It will be repeated to STDOUT.

1 Like

In these examples the cat and echo give the same output but do not work the same. cat contatenates files and prints to standard output. In the example, cat is followed by << which is redirection operator. cat will concatenate all text until the closing label is found. In this case the EOF. echo displays a line of text to standard output.

1 Like