Mahdi Archin Mahdi Archin - 3 months ago 16
Linux Question

One redirection operator is not clear to me and that is <<

The usage of

<<
is not clear to me, can anyone explain this with a simple example? really appreciate that.

Answer
cat <<'EOF'
hello $$
I'm a here document that doesn't interpolate
any $-variables because of the qutoes around
the EOF marker
EOF

echo -------

cat <<EOF
hello $$
I'm a here document that does interpolate
EOF

echo -------

cat <<x
It doesn't matter what you use as the end of file marker
x

echo -------

cat <<'x'
Quotes prevent $-interpolation
x

Output:

hello $$
I'm a here document that doesn't interpolate
any $-variables because of the qutoes around
the EOF marker
-------
hello 29843
I'm a here document that does interpolate
-------
It doesn't matter what you use as the end of file marker
-------
Quotes prevent $-interpolation