Skip to content
koalaman edited this page Feb 8, 2014 · 19 revisions

Use $(..) instead of deprecated `..`

Problematic code:

echo "Current time: `date`"

Correct code:

echo "Current time: $(date)"

Rationale:

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

  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.

Contraindications

None.

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