bug-bash
[Top][All Lists]
Advanced

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

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


From: Chet Ramey
Subject: Re: strange expansion of <(cat p.main.{optional,extra})
Date: Tue, 17 Apr 2007 20:16:53 -0400
User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326)

address@hidden 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 you want the brace expansion deferred until the subshell executes, you
have to explicitly say so:

cat <(eval cat /etc/\{passwd,motd})

The backslash suppresses brace expansion in the parent shell; the eval
forces it in the subshell.  (The backslash is passed through to the
subshell.)

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




reply via email to

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