Re: Arithmetic expansion with increments and output redirection
From:
Andreas Schwab
Subject:
Re: Arithmetic expansion with increments and output redirection
Date:
Wed, 24 Apr 2019 15:07:53 +0200
User-agent:
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)
On Apr 24 2019, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> On Wed, Apr 24, 2019 at 06:47:41AM -0600, 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.
>
> The context got snipped but IIRC it was something like
>
> /bin/true > $((n++))
>
> The /bin/true forces the use of an external command, which means a subshell
> is forked. The redirection occurs in the forked subshell.
But the expansion isn't required to be performed in the subshell. I
don't see POSIX having any wording to require one or the other. Doing
the expansion before the fork looks reasonable, even if only to make it
consistent with builtins.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."