Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Andreas Schwab
Chet Ramey <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
>
>> Bash Version: 3.1
>> Patch Level: 17
>> Release Status: release
>> 
>> Description:
>> Hi,
>> 
>> The expansion of echo <(cat /etc/{passwd,motd}) is rather surprising:
>> $  echo <(cat p.main.{optional,extra})
>> ++ cat p.main.optional
>> cat: p.main.optional: No such file or directory
>> ++ cat p.main.extra
>> cat: p.main.extra: No such file or directory
>> + echo /dev/fd/63 /dev/fd/62
>> /dev/fd/63 /dev/fd/62
>> 
>> I would have expected to be expanded to <(cat /etc/passwd /etc/motd) first.
>
> That's not how it works.  Brace expansion is the first expansion performed.
> The manual page says:
>
> "Brace expansion is performed before any other expansions, and any char-
> acters special to other expansions are preserved in the result.  It  is
> strictly  textual.  Bash does not apply any syntactic interpretation to
> the context of the expansion or the text between the braces."

If it would be done strictly textual, the resulting expansion would
actually be this:

$ echo <(cat p.main.optional) p.main.extra)

which would be a syntax error.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Lucas Nussbaum
On 18/04/07 at 11:11 +0200, Andreas Schwab wrote:
> Chet Ramey <[EMAIL PROTECTED]> writes:
> 
> > [EMAIL PROTECTED] wrote:
> >
> >> Bash Version: 3.1
> >> Patch Level: 17
> >> Release Status: release
> >> 
> >> Description:
> >> Hi,
> >> 
> >> The expansion of echo <(cat /etc/{passwd,motd}) is rather surprising:
> >> $  echo <(cat p.main.{optional,extra})
> >> ++ cat p.main.optional
> >> cat: p.main.optional: No such file or directory
> >> ++ cat p.main.extra
> >> cat: p.main.extra: No such file or directory
> >> + echo /dev/fd/63 /dev/fd/62
> >> /dev/fd/63 /dev/fd/62
> >> 
> >> I would have expected to be expanded to <(cat /etc/passwd /etc/motd) first.
> >
> > That's not how it works.  Brace expansion is the first expansion performed.
> > The manual page says:
> >
> > "Brace expansion is performed before any other expansions, and any char-
> > acters special to other expansions are preserved in the result.  It  is
> > strictly  textual.  Bash does not apply any syntactic interpretation to
> > the context of the expansion or the text between the braces."
> 
> If it would be done strictly textual, the resulting expansion would
> actually be this:
> 
> $ echo <(cat p.main.optional) p.main.extra)
> 
> which would be a syntax error.

Well, no, because bash expands *parameters*, not words. So the prefix is
"<(cat /etc/", and the suffix is ")".
-- 
| Lucas Nussbaum
| [EMAIL PROTECTED]   http://www.lucas-nussbaum.net/ |
| jabber: [EMAIL PROTECTED] GPG: 1024D/023B3F4F |


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Andreas Schwab
Lucas Nussbaum <[EMAIL PROTECTED]> writes:

> Well, no, because bash expands *parameters*, not words. So the prefix is
> "<(cat /etc/", and the suffix is ")".

But that would not be a *strict textual* expansion.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Andreas Schwab on 4/18/2007 4:01 AM:
> Lucas Nussbaum <[EMAIL PROTECTED]> writes:
> 
>> Well, no, because bash expands *parameters*, not words. So the prefix is
>> "<(cat /etc/", and the suffix is ")".
> 
> But that would not be a *strict textual* expansion.

According to 'man bash', brace expansion is documented as being able to
expand one word into many.  <(...) forms a single word, even when ...
contains unquoted spaces.  Therefore, strict textual expansion occurred,
and there was no syntax error.

- --
Don't work too hard, make some time for fun as well!

Eric Blake [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGJgwE84KuGfSFAYARAgF/AJ0VUlTUe/SoCsHOEKKsNk/D4bQXhwCfbWYU
ba0721NvVacYWFWx4ldk4Ng=
=PmOq
-END PGP SIGNATURE-


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Andreas Schwab
Eric Blake <[EMAIL PROTECTED]> writes:

> According to Andreas Schwab on 4/18/2007 4:01 AM:
>> Lucas Nussbaum <[EMAIL PROTECTED]> writes:
>> 
>>> Well, no, because bash expands *parameters*, not words. So the prefix is
>>> "<(cat /etc/", and the suffix is ")".
>> 
>> But that would not be a *strict textual* expansion.
>
> According to 'man bash', brace expansion is documented as being able to
> expand one word into many.

The documentation talks about strings, not words.

> <(...) forms a single word, even when ...  contains unquoted spaces.

That requires syntactic interpretation to the context of the expansion,
which is explicitly excluded.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Stephane Chazelas
On Tue, Apr 17, 2007 at 08:16:53PM -0400, Chet Ramey wrote:
[...]
> > The expansion of echo <(cat /etc/{passwd,motd}) is rather surprising:
> > $  echo <(cat p.main.{optional,extra})
> > ++ cat p.main.optional
> > cat: p.main.optional: No such file or directory
> > ++ cat p.main.extra
> > cat: p.main.extra: No such file or directory
> > + echo /dev/fd/63 /dev/fd/62
> > /dev/fd/63 /dev/fd/62
> > 
> > I would have expected to be expanded to <(cat /etc/passwd /etc/motd) first.
> 
> That's not how it works.  Brace expansion is the first expansion performed.
> The manual page says:
> 
> "Brace expansion is performed before any other expansions, and any char-
> acters special to other expansions are preserved in the result.  It  is
> strictly  textual.  Bash does not apply any syntactic interpretation to
> the context of the expansion or the text between the braces."
[...]

How does it get exanded to

echo <(cat p.main.optional) <(cat p.main,extra)

though?

If it were textual, I would expect:

echo <(cat p.main.optional) p.main,extra)

And what about:

echo $(cat p.main.{optional,extra})

This resolves to

echo $(cat p.main.optional p.main.extra)

I can't see any reason why $(...) and <(...) should be treated
differently.

bash-3.1$ echo <(echo {a,b})
++ echo a
++ echo b
+ echo /dev/fd/63 /dev/fd/62
/dev/fd/63 /dev/fd/62
bash-3.1$ echo $(echo {a,b})
++ echo a b
+ echo a b
a b


All the other shells treat them the same in that regards.

Any expansion inside command or process subsitution should
be defered to the subshell I think. 

% echo <(echo {a,b})
+zsh:1> echo a b
+zsh:1> echo /proc/self/fd/11
/proc/self/fd/11
% echo $(echo {a,b})
+zsh:1> echo a b
+zsh:2> echo a b
a b

-- 
Stéphane


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Lucas Nussbaum
On 18/04/07 at 14:37 +0200, Andreas Schwab wrote:
> Eric Blake <[EMAIL PROTECTED]> writes:
> 
> > According to Andreas Schwab on 4/18/2007 4:01 AM:
> >> Lucas Nussbaum <[EMAIL PROTECTED]> writes:
> >> 
> >>> Well, no, because bash expands *parameters*, not words. So the prefix is
> >>> "<(cat /etc/", and the suffix is ")".
> >> 
> >> But that would not be a *strict textual* expansion.
> >
> > According to 'man bash', brace expansion is documented as being able to
> > expand one word into many.
> 
> The documentation talks about strings, not words.

Based on the behaviour, I think that bash first splits the command line
into a list of parameters, then expands each parameter. <(...) is a
single parameter.
-- 
| Lucas Nussbaum
| [EMAIL PROTECTED]   http://www.lucas-nussbaum.net/ |
| jabber: [EMAIL PROTECTED] GPG: 1024D/023B3F4F |


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: strange expansion of <(cat p.main.{optional,extra})

2007-04-18 Thread Chet Ramey
Stephane Chazelas wrote:
> On Tue, Apr 17, 2007 at 08:16:53PM -0400, Chet Ramey wrote:

> How does it get exanded to
> 
> echo <(cat p.main.optional) <(cat p.main,extra)
> 
> though?
> 
> If it were textual, I would expect:
> 
> echo <(cat p.main.optional) p.main,extra)

It's still a word expansion.  The parser splits the input into words
before brace expansion takes place.

> 
> And what about:
> 
> echo $(cat p.main.{optional,extra})
> 
> This resolves to
> 
> echo $(cat p.main.optional p.main.extra)
> 
> I can't see any reason why $(...) and <(...) should be treated
> differently.

Yes, that's a separate issue worth consideration.  There is already code
to treat command substitution specially and defer expansion to the
subshell.  It might be a good idea to treat process substitution the same
way.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash