On 4/24/19 9:22 AM, Ian Neal wrote: > On Wed, Apr 24, 2019, 07:12 Chet Ramey <chet.ra...@case.edu > <mailto:chet.ra...@case.edu>> 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" http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_12 > 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 c...@case.edu http://tiswww.cwru.edu/~chet/