Created
August 14, 2020 00:18
-
-
Save webern/c213dc00c8bbb79be98ee7e8179561e1 to your computer and use it in GitHub Desktop.
I can never remember how to do heredocs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# heredoc with shell expansion | |
cat << EOF | |
The current working directory is: $PWD | |
You are logged in as: $(whoami) | |
EOF | |
# heredoc with shell expansion into a variable | |
myvar=$(cat << EOF | |
The current working directory is: $PWD | |
You are logged in as: $(whoami) | |
EOF | |
) | |
echo "${myvar}" | |
# heredoc without shell expansion (the delimiter has quotes) | |
cat <<- "EOF" | |
The current working directory is: $PWD | |
You are logged in as: $(whoami) | |
EOF | |
# heredoc without shell expansion (the delimiter has quotes) | |
myvar2=$(cat <<- "EOF" | |
The current working directory is: $PWD | |
You are logged in as: $(whoami) | |
EOF | |
) | |
echo "${myvar2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment