Skip to content

here doc

basic here document (stdin redirection)
cat <<MARKER
    $(date) foobar
MARKER
supress parameter and command substitution
cat <<'MARKER'
    $(date) foobar
MARKER
suppress leading tabs
cat <<-MARKER
    $(date) foobar
MARKER
write here document to file
cat >file <<EOT
    $(date) foobar
EOT
assign here document to variable
FOOBAR=$(cat <<EOT
        foobar farboo barfoo boofar 
EOT
)
examples
here document to stderr
cat >&2 <<EOT
usage: script [-h] [-f] /path/to/file
h - help
f - foobar
EOT
ssh session
ssh remote-host <<EOT
echo "local working directory: $PWD"
echo "remote working directory: \$PWD"
uptime
EOT
ex session
ex file <<EOT
:%s/foobar/boofar/g
:wq
EOT
vi session
vi file <<EOT
i
foo
bar
^[
:wq
EOT
ctrl+v esc generates ^[

https://tldp.org/LDP/abs/html/here-docs.html


last updated: Sat Aug 12 14:29:24 2023

Back to top