bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spaces in args, escapes, and command substitution


From: Eric Blake
Subject: Re: Spaces in args, escapes, and command substitution
Date: Sat, 28 Oct 2006 22:55:38 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to bash@zacglen.com on 10/28/2006 10:19 PM:
>> That's because `` and $() have different syntax, as required by POSIX.
>> You should just do $(basename "$f1"), rather than $(basename \"$f1\").
>>
> 
> That's crazy!
> 
> You have nested double quotes which don't need escaping?!

Correct.  Go read the POSIX spec:
http://www.opengroup.org/onlinepubs/009695399/idx/shell.html

In particular,
"With the $( command) form, all characters following the open parenthesis
to the matching closing parenthesis constitute the command. Any valid
shell script can be used for command, except a script consisting solely of
redirections which produces unspecified results."

$() was invented because it is much easier to write normal shell scripts,
without worrying about the extra escapes that are required by ``.

> 
> Let me think aloud:
> 
>     The first thing one encounters left-to-right is a double-quote.
>     So, logic says that the quoted string is terminated by matching
>     double-quote.

No, when encountering ", one follows certain rules while looking for the
closing quote, and one of those rules is:
"The input characters within the quoted string that are also enclosed
between "$(" and the matching ')' shall not be affected by the
double-quotes, but rather shall define that command whose output replaces
the "$(...)" when the word is expanded. The tokenizing rules in Token
Recognition , not including the alias substitutions in Alias Substitution
, shall be applied recursively to find the matching ')'."

> Looks like POSIX and commonsense are two different things.

Like it or not, POSIX standardized the original bourne shell `` behavior,
as well as the ksh $() behavior, and the two behaviors are different.  Get
used to it.

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFRDRJ84KuGfSFAYARAmTtAKCcjQBFCmg9mbLbCaiSM7FESgYiogCgtot8
+OwN8s0+jojCpvrcrugWiHw=
=KOED
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]