Expressions do not expand in single quotes

Single-quoted strings are literal. If you want `$var` to expand, switch to double quotes.

Problem

Single quotes preserve every character literally — including ` SC2016: Expressions do not expand in single quotes . This rule fires when ShellCheck spots what looks like a variable or command substitution inside single quotes, which is usually a typo for double quotes.

Bad

name=world
echo 'Hello, $name'   # prints: Hello, $name

Good

name=world
echo "Hello, $name"   # prints: Hello, world

Explanation

When you genuinely want literal ` SC2016: Expressions do not expand in single quotes (passing a sed expression, awk script, or password), confirm with a comment so future readers know the choice was deliberate.

When It Matters

Single quotes are literal in Bash: no variable expansion, no command substitution, no history expansion. Writing echo 'Deploying $version' prints the dollar sign and the word "version" instead of the value, and the mistake usually escapes review because the line looks correct at a glance. Most real occurrences come from copying a line that legitimately needed single quotes — an awk program, a jq filter, an ssh remote command — and then adding a local variable to it without changing the quoting.

Second Example

Note

awk -v is the correct way to get a shell value into an awk program without breaking the single quotes that protect awk’s own $1 and $3.

Exceptions

Whenever the dollar sign belongs to another language, single quotes are correct and the warning is a false positive: awk field references, jq filters, sed with \1 backreferences, Perl or Python one-liners, and remote commands whose variables must be expanded on the far end of an ssh connection. Add "# shellcheck disable=SC2016" above the line to record that the literal is intentional.

Faq

Q

How do I include a literal dollar sign inside double quotes?

A

Escape it: "costs \$5". Inside double quotes the backslash suppresses expansion for $, `, ", \ and newline.

Q

How do I mix expanded and literal parts in one argument?

A

Adjacent quoted strings concatenate with no separator: 'literal $keep'"$expand"'more literal'. The shell joins them into a single word.

Q

Which variables expand when I run ssh host "echo $HOME"?

A

Double quotes expand $HOME locally, so you send your own home path. Use single quotes to have the remote shell expand it instead.