help-bash
[Top][All Lists]
Advanced

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

Re: i vote for $( .. <file ) be available also as non first command in s


From: Chet Ramey
Subject: Re: i vote for $( .. <file ) be available also as non first command in subshells ( and maybe process subst ) ?
Date: Fri, 12 Mar 2021 10:15:03 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.0

On 3/12/21 8:10 AM, Greg Wooledge wrote:

OK, first things first: $(<file) is special syntax.  It is defined to
be equivalent to $(cat file), except that it doesn't need to exec cat(1),
so it is marginally more efficient.

Sort of, but not in the way you think. It's not an operator, nor is it
determined lexically.  In other words, it is not this:

> It's
> a new piece of syntax that consists of three characters, but you're
> allowed to put whitespace between the second and third character.

but rather a command substitution that contains a single simple command
that consists solely of a single input redirection. This requires parsing
it, which currently happens in the subshell since that's where command
substitutions are parsed.

It looks more like this pseudo-regexp:

$\([[:blank:]]*<([!<&->]|[[:blank:]]*)[![:blank:])]*.*\)

but that doesn't exactly capture it since it doesn't take into account the
fact that `file' can be quoted, and it's tricky to capture the restriction
that the character immediately following the `<' can be anything but a
character that defines a different redirection operator. I need better
regexp-fu to write the correct one.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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