bug-bash
[Top][All Lists]
Advanced

[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 10:36:33 -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 10:20 AM, Ian Neal wrote:
>     "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"
> 
>     
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_12
> 
> The utility here in question is the external command (/bin/true in my
> example), which doesn't do the expansion itself. In this case, it's not the
> utility affecting the environment, it's the expansion performed by the
> (sub)shell itself before the exec*() that has an effect on the environment.

I think the POSIX language is crafted to allow both behaviors, and bash has
always interpreted it to mean that the redirections are processed,
including any word expansions specified, in the child process forked to
execute the command.

> 
> 
>     They're different from word expansions.
> 
> The bash manual calls it a word, which is one of the sources of my confusion.
> "The general format for redirecting output is:
> 
> [n]>word"

Imprecise language. Let's see if I can do better. A word has a specific
definition, which is given earlier in the man page. It determines which
characters make up the token following the redirection operator.

That word undergoes a set of expansions, which are also specified. These
are a subset of the full set of expansions a word that is not part
of a redirection undergoes (for example, non-interactive shells don't
perform globbing on the word in a redirection, and word splitting is never
performed). These are performed separately, and not at the same time as
the expansions on a word that is an argument to a simple command. In fact,
there was a debate over whether or not the effects of the other word
expansions are visible to the expansions performed when processing
redirections. That's what I mean when I say they're different from word
expansions.

-- 
``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]