[prev in list] [next in list] [prev in thread] [next in thread] 

List:       netbsd-tech-userlevel
Subject:    Re: sh: unbalanced ' in ` not detected
From:       Alan Barrett <apb () cequrux ! com>
Date:       2007-10-30 17:15:51
Message-ID: 20071030171551.GA1105 () apb-laptoy ! apb ! alt ! za
[Download RAW message or body]

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)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic