-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2006
Jari Aalto edited this page Feb 3, 2025
·
21 revisions
echo "You are running on `uname`"
echo "You are running on $(uname)"
Backtick command substitution `...`
is legacy syntax with several issues.
- It has a series of undefined behaviors related to quoting in POSIX.
- It imposes a custom escaping mode with surprising results.
- 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.
- Some very old, legacy sh implementations, may not support
$(...)
and might require the use of backtick command substitution. See [mc-devel] [PATCH] Prefer $() to backticks in sh script and follow-ups.
- BashFaq: Why is
$(...)
preferred over`...`
(backticks)? - StackOverflow: What is the difference between $(command) and
`command`
in shell programming? - shfmt will automatically convert the legacy syntax