Subject: Re: sh: unbalanced ' in ` not detected
To: None <>
From: Alan Barrett <>
List: tech-userlevel
Date: 10/30/2007 10:15:51
On Tue, 30 Oct 2007, Christos Zoulas wrote:
> > 	echo `echo 'foo`
> file a PR. sh is even funnier if you try echo $(echo 'foo)

The quoting rules for `...` and $(...) are very different.  In the case
of `...`, backslashes are the only recognised quoting mechanism, and
nested `...` constructs require backslashes.  In the case of $(...),
all kinds of quoting may be used, and nested $(...) constructs do not
requore any quoting.  NetBSD's /bin/sh man page does a bad job of
explaining this.

So, considering the examples here, in the <`echo 'foo`> case, the two
<`> characters are a matched pair, and the embedded <'> is unmatched.
In the <$(echo 'foo)> case, the <$(> and the <)> are not a matched
pair -- the <)> is just an ordinary character inside the un-terminated
single-quoted string.

NetBSD's /bin/sh seems to get the "$(...)" case right.

--apb (Alan Barrett)