Skip to content

Instantly share code, notes, and snippets.

@paradigm
Created September 9, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paradigm/24cd644e9b7beafcc7e6f220d53d7449 to your computer and use it in GitHub Desktop.
Save paradigm/24cd644e9b7beafcc7e6f220d53d7449 to your computer and use it in GitHub Desktop.
heredoc explanation
$ # literal because it's a single-quote string
$ echo '$HOME'
$HOME
$ # interpreted because it's a double-quote string
$ echo "$HOME"
/home/paradigm
$ # interpreted again because it's a double-quote string despite containing single quotes within it
$ echo "'$HOME'"
'/home/paradigm'
$ # to print the literal with the interpreted string, have to escape
$ echo "\$HOME"
$HOME
$ # interpreted because it's a heredoc
$ cat <<EOF
heredoc> $HOME
heredoc> EOF
/home/paradigm
$ # interpreted again because it's a here-doc despite containing single quotes within it
$ cat <<EOF
heredoc> '$HOME'
heredoc> EOF
'/home/paradigm'
$ # to print the literal with the interpreted string, have to escape
$ cat <<EOF
heredoc> \$HOME
heredoc> EOF
$HOME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment