sh(1): Describe subshell environment, command substitution more correctly.

POSIX does not require the shell to fork for a subshell environment, and we
use that possibility in various ways (command substitutions with a single
command and most subshells that are the final command of a shell process).
Therefore do not tie subshells to forking in the man page.

Command substitutions with expansions are a bit strange, causing a fork for
$(...$(($x))...) because $x might expand to y=2; they will probably be
changed later but this is how they work now.
This commit is contained in:
Jilles Tjoelker 2011-03-20 23:52:45 +00:00
parent a34287fbad
commit ef89d04f13
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219806

View File

@ -32,7 +32,7 @@
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
.\" $FreeBSD$
.\"
.Dd February 8, 2011
.Dd March 20, 2011
.Dt SH 1
.Os
.Sh NAME
@ -934,9 +934,9 @@ or
.Pp
.D1 Li { Ar list Ns Li \&; }
.Pp
The first form executes the commands in a subshell.
The first form executes the commands in a subshell environment.
Note that built-in commands thus executed do not affect the current shell.
The second form does not fork another shell,
The second form never forks another shell,
so it is slightly more efficient.
Grouping commands together this way allows the user to
redirect their output as though they were one program:
@ -1450,8 +1450,8 @@ or the backquoted version:
.Pp
.D1 Li ` Ns Ar command Ns Li `
.Pp
The shell expands the command substitution by executing command in a
subshell environment and replacing the command substitution
The shell expands the command substitution by executing command
and replacing the command substitution
with the standard output of the command,
removing sequences of one or more newlines at the end of the substitution.
Embedded newlines before the end of the output are not removed;
@ -1459,6 +1459,18 @@ however, during field splitting, they may be translated into spaces
depending on the value of
.Va IFS
and the quoting that is in effect.
The command is executed in a subshell environment,
except that the built-in commands
.Ic jobid ,
.Ic jobs ,
.Ic times
and
.Ic trap
return information about the main shell environment
if they are the only command in a command substitution
and the substitutions in the command cannot cause side effects
(such as from assigning values to variables or referencing
.Li $! ).
.Ss Arithmetic Expansion
Arithmetic expansion provides a mechanism for evaluating an arithmetic
expression and substituting its value.
@ -2265,8 +2277,8 @@ Omitting the
.Ar action
is another way to request the default action, for compatibility reasons this
usage is not recommended though.
When the shell forks off a subshell,
it resets trapped (but not ignored) signals to the default action.
In a subshell environment,
the shell resets trapped (but not ignored) signals to the default action.
The
.Ic trap
command has no effect on signals that were ignored on entry to the shell.