Bash Input/Output: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:


=Echo Multiple Lines to <tt>stdout</tt>=
=Echo Multiple Lines to <tt>stdout</tt>=
<pre>
cat <<EOF
  blah
  ${some_var}
  blah
EOF
</pre>
* It will perform variable substitution. If you don't want that, escape <tt>\${some_var}</tt>.
* <tt>`...`</tt> sequences should be escaped as shown here: <tt>\`...\`</tt> otherwise they will executed before the output is sent to stdout.
* \ will join lines. If you want "\" in the output, then you should escape it:
<pre>
      ...
      blah blah \\
      ...
</pre>


=Echo Multiple Lines into a File=
=Echo Multiple Lines into a File=
<pre>
(cat << EOF
blah
EOF
) > /tmp/test.txt
</pre>

Revision as of 02:49, 22 February 2016

Internal


Echo Multiple Lines to stdout

cat <<EOF
  blah
  ${some_var}
  blah
EOF
  • It will perform variable substitution. If you don't want that, escape \${some_var}.
  • `...` sequences should be escaped as shown here: \`...\` otherwise they will executed before the output is sent to stdout.
  • \ will join lines. If you want "\" in the output, then you should escape it:
      ...
      blah blah \\
      ...

Echo Multiple Lines into a File

(cat << EOF
blah
EOF
) > /tmp/test.txt