Contents

10/06/2026

Backticks in a Double-Quoted Shell String Run as Commands

Short answer: in a POSIX shell such as bash, a backtick inside double quotes starts command substitution. The shell runs whatever is between the backticks and puts its output in the string, so the words you wrote disappear. Use single quotes, a quoted here-document or a file instead. In PowerShell the backtick is an escape character, which is a different rule.

What happens

You write a commit message or a comment in double quotes and mark a command name with backticks, the way you would in Markdown:

msg="Fixed the build, ran `echo SURPRISE` and the `git status` check"
echo "$msg"

We ran this in GNU bash 5.3.9 on Windows. The output was:

fatal: not a git repository (or any of the parent directories): .git
Fixed the build, ran SURPRISE and the  check

The shell ran echo SURPRISE and git status, replaced each pair of backticks with their output, and printed the result. The words echo and git status vanished, and git status also ran in whatever folder you were in, with its error going to your screen. The text was changed, no error stopped it and the command that ran may have done something.

Why

The POSIX shell specification says that inside double quotes "the backquote shall retain its special meaning introducing the other form of command substitution" (The Open Group: Shell Command Language, 2.2.3 Double-Quotes, Issue 7, 2018 edition). The other form is $(...). Single quotes do not have that rule.

Four ways to keep the backticks

msg='Fixed the build, ran `echo SURPRISE` and the `git status` check'   # single quotes
msg="Fixed the build, ran \`echo SURPRISE\` and the \`git status\` check" # escaped

We tested both, and each printed the backticks unchanged. A third way is a here-document with a quoted delimiter, which stops the shell expanding anything inside it, and a fourth is to put the text in a file and pass the file.

cat <<'TXT'
literal with `backticks` kept
TXT

Pick the one that fits

  • Single quotes

    Simplest. Breaks only if the text itself contains a single quote.

  • Backslash before each backtick

    Works inside double quotes. Easy to miss one.

  • Quoted here-document

    Best for long, multi-line text. Quote the delimiter: <<'TXT'.

  • A file

    For tools that accept one, such as a body or message file. Nothing for the shell to expand.

Where it bites

  • Commit messages and issue comments written from the command line with -m "..." or --body "...".
  • Scripts that build text for a log or an email.
  • Anything an AI tool writes for you. Markdown uses backticks for code, so generated command-line text is full of them.

PowerShell is different

In PowerShell the backtick is the escape character, not command substitution. We ran this in Windows PowerShell:

"ran `echo SURPRISE` done"   prints   ran echo SURPRISE done
"tab:`tX"                    prints   tab:  X

Nothing was executed, and a backtick before a t became a tab. Copying a bash habit into PowerShell, or the reverse, is where people get surprised.

FAQ

Why does my commit message lose words in backticks?

In bash, backticks inside double quotes run the text between them as a command and replace it with the output. Use single quotes, escape each backtick or read the message from a file.

How do I put a backtick in a double-quoted string?

Put a backslash before it, or use single quotes. In a here-document, quote the delimiter so nothing inside is expanded.

Is the backtick special in PowerShell?

Yes, but differently. It is the escape character, so a backtick in a double-quoted string does not run a command.

Researched and drafted with AI, then reviewed and edited by the site's editors.

Filed under