9

The modern recommendation is to use:

$(...)

instead of the older:

`...`

mainly for readability and to avoid the need for escaping when nesting.

Which shells do not support the $(...) form, and are any of them still in use today?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
joeytwiddle
  • 1,008
  • 9
  • 15
  • 1
    Read through [Have backticks (i.e. `cmd`) in *sh shells been deprecated?](http://unix.stackexchange.com/questions/126927/have-backticks-i-e-cmd-in-sh-shells-been-deprecated) and you will find the answer. – John1024 Jul 24 '15 at 05:11
  • It says "The only reason for using backticks is for compatibility with a real Bourne shell (like Heirloom)." – joeytwiddle Jul 24 '15 at 14:31
  • 1
    One important point is that all maintained post-90's Unix-like systems will have a command called `sh` which in the right environment will support `$(...)`. – Stéphane Chazelas Aug 24 '15 at 11:30

2 Answers2

8

The original Bourne shell, csh or tcsh all do not support $() and require `` for command substitution.

The Bourne shell is no longer used as the default shell (/bin/sh) on many UNIX based operating systems. However, these shells are still supplied by the OS vendors as they are still used for historical reasons.

Both AIX and HP-UX have /bin/sh as a POSIX compliant shell. Bourne shell is still available on AIX as 'bsh' (but deprecated in 1995 with AIX 4.1) and HP-UX 11.11 '/usr/old/bin/sh' (Bourne was removed from 11.23). I'm not sure when the switch was made, but it was many years ago.

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
5

The Solaris 10 and earlier /bin/sh does not support $().

It is still in use today because Solaris 10 is still in use, Sun did not want to replace it with a standard conforming version (up to and including Solaris 10) - and because most people consider /bin/sh as the default shell and don't know how to portably execute a script with a POSIX conforming shell.

Sun's motivation for not changing /bin/sh was to avoid breaking existing shell scripts that rely on the non-conforming behavior.

maxschlepzig
  • 56,316
  • 50
  • 205
  • 279
  • 2
    @cuonglm, yes, I just tested it and I can confirm it. Would have thought that rather Hurd is going to be released than Sun/Oracle changes its policy on `/bin/sh` ... – maxschlepzig Jul 24 '15 at 07:02