# stdout → stderr
>&2 echo "foo"
echo "foo" 1>&2
# stderr → stdout
echo "foo" 2>&1
# when combining with other redirects,
# stdout/stderr must come last. E.g. suppress all output:
{ echo "foo"; >&2 echo "bar"; } >/dev/null 2>&1
Stdout as file-input
cat <(ls -l)
diff -y <(ls) <(ls -a)
Any string as stdin:
read -r <<< Hello
read -r <<< "$PATH"
read -r <<< "$(ls -l)"
Multiline string as stdin:
cat <<EOF
USER: ${USER}
HOME: ${HOME}
EOF
Without substitution:
cat <<'marker'
USER: ${USER}
HOME: ${HOME}
marker
Suppress leading tabs:
cat <<-EOF
Line 1
Line 2
EOF
Can be used with the null command to "comment out" blocks of code:
: <<COMMENT
echo "this will not run"
touch file
COMMENT