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:
parent
a34287fbad
commit
ef89d04f13
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219806
26
bin/sh/sh.1
26
bin/sh/sh.1
@ -32,7 +32,7 @@
|
|||||||
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
|
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd February 8, 2011
|
.Dd March 20, 2011
|
||||||
.Dt SH 1
|
.Dt SH 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -934,9 +934,9 @@ or
|
|||||||
.Pp
|
.Pp
|
||||||
.D1 Li { Ar list Ns Li \&; }
|
.D1 Li { Ar list Ns Li \&; }
|
||||||
.Pp
|
.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.
|
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.
|
so it is slightly more efficient.
|
||||||
Grouping commands together this way allows the user to
|
Grouping commands together this way allows the user to
|
||||||
redirect their output as though they were one program:
|
redirect their output as though they were one program:
|
||||||
@ -1450,8 +1450,8 @@ or the backquoted version:
|
|||||||
.Pp
|
.Pp
|
||||||
.D1 Li ` Ns Ar command Ns Li `
|
.D1 Li ` Ns Ar command Ns Li `
|
||||||
.Pp
|
.Pp
|
||||||
The shell expands the command substitution by executing command in a
|
The shell expands the command substitution by executing command
|
||||||
subshell environment and replacing the command substitution
|
and replacing the command substitution
|
||||||
with the standard output of the command,
|
with the standard output of the command,
|
||||||
removing sequences of one or more newlines at the end of the substitution.
|
removing sequences of one or more newlines at the end of the substitution.
|
||||||
Embedded newlines before the end of the output are not removed;
|
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
|
depending on the value of
|
||||||
.Va IFS
|
.Va IFS
|
||||||
and the quoting that is in effect.
|
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
|
.Ss Arithmetic Expansion
|
||||||
Arithmetic expansion provides a mechanism for evaluating an arithmetic
|
Arithmetic expansion provides a mechanism for evaluating an arithmetic
|
||||||
expression and substituting its value.
|
expression and substituting its value.
|
||||||
@ -2265,8 +2277,8 @@ Omitting the
|
|||||||
.Ar action
|
.Ar action
|
||||||
is another way to request the default action, for compatibility reasons this
|
is another way to request the default action, for compatibility reasons this
|
||||||
usage is not recommended though.
|
usage is not recommended though.
|
||||||
When the shell forks off a subshell,
|
In a subshell environment,
|
||||||
it resets trapped (but not ignored) signals to the default action.
|
the shell resets trapped (but not ignored) signals to the default action.
|
||||||
The
|
The
|
||||||
.Ic trap
|
.Ic trap
|
||||||
command has no effect on signals that were ignored on entry to the shell.
|
command has no effect on signals that were ignored on entry to the shell.
|
||||||
|
Loading…
Reference in New Issue
Block a user