Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is command substitution $(foo) bashism?

Tags:

bash

posix

sh

There are two different syntaxes for command substitution,

FOO=$(echo bar)

and

FOO=`echo bar`

As far as I know, the first method is defined in Bash, while the second is defined in sh.

Consider the following use of command substitution in an sh script.

#!/bin/sh
FOO=$(echo bar)

Does that fall under the definition of bashism?

bashisms, i.e. features not defined by POSIX (won't work in dash, or general /bin/sh).

like image 687
Lesmana Avatar asked Sep 24 '10 18:09

Lesmana


1 Answers

Actually, the $(...) command substitution syntax is defined by POSIX, though it's not part of the earlier SVID sh standard. So as long as you don't care about running on pre-POSIX systems, it should be fine.

like image 94
Chris Dodd Avatar answered Oct 08 '22 00:10

Chris Dodd