Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active March 12, 2024 11:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/451d2c2b3d36a0eaf350 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/451d2c2b3d36a0eaf350 to your computer and use it in GitHub Desktop.
BASH: Ways of Piping/Redirection and Heredoc Demonstration
# shells are an orchestration environment
# the language they provide is intended to orchestrate processes
# on the operating system
# if programs are functions, then all of the below are variants of function application
# anonymous pipe
echo "string" | cat
# herestring
cat <<< "string"
# herestring with command substitution
cat <<< $(echo "string")
# redirect stdin from process substitution
cat < <(echo "string")
# heredoc
cat << EOF
string
EOF
# heredoc ignoring leading tabs on each line
cat <<- EOF
string
EOF
# heredoc literal - ignores interpolation and evaluation
cat << 'EOF'
$string
EOF
@zffocussss
Copy link

heredoc with pipe

cat <<'EOF' |  sed 's/l/e/g'
Hello
World
EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment