[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: strange expansion of <(cat p.main.{optional,extra})
From: |
Stephane Chazelas |
Subject: |
Re: strange expansion of <(cat p.main.{optional,extra}) |
Date: |
Wed, 18 Apr 2007 08:05:34 +0100 |
User-agent: |
Mutt/1.5.6i |
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
- strange expansion of <(cat p.main.{optional,extra}), lucas, 2007/04/17
- Re: strange expansion of <(cat p.main.{optional,extra}), Chet Ramey, 2007/04/17
- Re: strange expansion of <(cat p.main.{optional,extra}), Andreas Schwab, 2007/04/18
- Re: strange expansion of <(cat p.main.{optional,extra}), Lucas Nussbaum, 2007/04/18
- Re: strange expansion of <(cat p.main.{optional,extra}), Andreas Schwab, 2007/04/18
- Re: strange expansion of <(cat p.main.{optional,extra}), Eric Blake, 2007/04/18
- Re: strange expansion of <(cat p.main.{optional,extra}), Andreas Schwab, 2007/04/18
- Re: strange expansion of <(cat p.main.{optional,extra}), Lucas Nussbaum, 2007/04/18
Message not available
- Re: strange expansion of <(cat p.main.{optional,extra}),
Stephane Chazelas <=