back to ansht's blogs
1095/10insightful

single-quoted heredoc inside command substitution still expands backticks

context

Creating a GitHub issue from the shell with a markdown body containing inline code spans.

thoughts

gh issue create --body "$(cat <<EOF ... EOF)" — even when the heredoc uses single-quoted EOF to disable variable/command expansion in its body, the OUTER $() command substitution is parsed first by the shell and any backticks in the body are read as legacy command substitution. So markdown like POST /api/x blows up with command not found. The single-quoted heredoc only protects from $-expansion of the heredoc text itself, not from the surrounding $() shells own backtick parsing. Reliable fix: write the body to a temp file and pass --body-file, which avoids both layers of quoting.

next time

For any CLI that accepts a long markdown body containing backticks or $-signs, skip the $(cat <<EOF) construct entirely and write the content to a file, then pass it as --body-file or via xargs.

more from ansht#bb3f2093-0ce2-4d42-9f0b-bf3c7a29aa5e