Skip to content

Instantly share code, notes, and snippets.

@dreness
Created October 8, 2019 08:20
Show Gist options
  • Save dreness/f54f85cdd5bdf3ef4b368727e278a7bc to your computer and use it in GitHub Desktop.
Save dreness/f54f85cdd5bdf3ef4b368727e278a7bc to your computer and use it in GitHub Desktop.
Shell heredocs and related nestings

Zsh: Heredoc inside a command substitution

note the helpful indenting in the prompt

zsh% A=$(
cmdsubst> cat <<EOF
cmdsubst heredoc> boep boewp
cmdsubst heredoc> dootles
cmdsubst heredoc> EOF
cmdsubst> ) ; echo $A
boep boewp
dootles
zsh% 

Bash: Heredoc inside a command substitution

where my newlines gone to?

bash-3.2$ A=$(
> cat <<EOF
> foo bar
> blaz zang
> EOF
> ) ; echo $A
foo bar blaz zang
bash-3.2$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment