[Top][All Lists]

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

Re: Arithmetic expansion with increments and output redirection

From: Chet Ramey
Subject: Re: Arithmetic expansion with increments and output redirection
Date: Wed, 24 Apr 2019 09:37:43 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

On 4/24/19 9:22 AM, Ian Neal wrote:
> On Wed, Apr 24, 2019, 07:12 Chet Ramey <address@hidden
> <mailto:address@hidden>> wrote:
>     On 4/24/19 8:47 AM, Ian Neal wrote:
>     > At what point is a subshell being invoked? There's no pipeline, command
>     > substitution, coprocess, background process, or explicit () subshell
>     here,
>     > which are the only cases a subshell should be created. Otherwise, the
>     > entire operation should be evaluated by the main shell. Arithmetic
>     > expansion is not in that list.
>     Why would you think that /bin/true would be "evaluated by the main shell?"
>     It's not a shell compound command or a builtin, and non-builtin commands
>     are run in child processes.
> Calling what should be a simple fork(); exec(); a "subshell" is a little
> disingenuous 

It's the exact definition of a subshell.

"Utilities other than the special built-ins (see Special Built-In
Utilities) shall be invoked in a separate environment that consists of the
following...[includes redirections specified to the utility]...The
environment of the shell process shall not be changed by the utility"


> unless it has its own parameter expansion options, which isn't
> true -- if the $((n++)) was on the left side of the file redirection (which
> is to say a parameter), it would be expanded by the shell before the
> fork(), so why is this true with the redirection itself? 

Because that's how redirections are performed, and how the shell has
historically behaved (the Bourne shell, in fact, performed any command
with a redirection in a subshell, including builtins and compound
commands). They're different from word expansions.

What makes that
> case so special? I posit that it shouldn't be.

That redirections should be processed by the main shell before forking?
Since they're not allowed to affect the shell environment, what would be
gained by doing this, other than having to go through the extra work of
undoing them?

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

reply via email to

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