It is my understanding that the more modern $(...)
command substitution syntax is preferred over the old `
-based syntax, due to easier and less error-prone nesting and escaping syntax.
Further, it seems that most /bin/sh
-style shells in modern use support $(…)
:
- bash
- ash (and therefore BusyBox, so most embedded Linux)
- dash
- FreeBSD /bin/sh
And $(…)
is specified by IEEE 1003.1.
So I have 2 very related questions:
- Is there any reason to use ` in new development of shell scripts unless you know of a specific old system that the script will need to run on?
- Is there any reason not to teach UNIX programming students just to write
$(...)
, and discuss`
only as an obsolete variant that they will likely encounter if they are reading other developers' shell scripts (and may need if they are working with a really old system or nonstandard for some reason)?
\
...``. It's there for backward portability with the Bourne shell only (like the Bourne shell had^
(same as|
) for backward portability with the Thomson shell). Note however that(t)csh
don't have$(...)
(but there's no much point using or teaching them either). – Stéphane Chazelas Jan 21 '15 at 21:26$()
- shift+4,9, shift+0 - 5 key presses; – Vi. Jan 22 '15 at 17:18