Skip to content
koalaman edited this page Jan 25, 2015 · 19 revisions

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

Problematic code:

echo "Current time: `date`"

Correct code:

echo "Current time: $(date)"

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.

Exceptions

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