Skip to content
Jari Aalto edited this page Feb 3, 2025 · 21 revisions

Use $(...) notation instead of legacy backticked `...`.

Problematic code

echo "You are running on `uname`"

Correct code

echo "You are running on $(uname)"

Rationale

Backtick command substitution `...` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(...) command substitution has none of these problems, and is therefore strongly encouraged.

Note: The $(...) syntax was introduced in the 1989 Korn Shell (ksh). Finally, in 2011, Solaris 11 was the last operating system to switch from the Bourne Shell to the Korn Shell. After 2011, all typical shells have supported the POSIX $(...) notation.

Exceptions

Related resources:

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally