svn commit: r219806 - head/bin/sh

Jilles Tjoelker jilles at
Sun Mar 20 23:52:45 UTC 2011

Author: jilles
Date: Sun Mar 20 23:52:45 2011
New Revision: 219806

  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.


Modified: head/bin/sh/sh.1
--- head/bin/sh/sh.1	Sun Mar 20 22:47:41 2011	(r219805)
+++ head/bin/sh/sh.1	Sun Mar 20 23:52:45 2011	(r219806)
@@ -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
@@ -934,9 +934,9 @@ or
 .D1 Li { Ar list Ns Li \&; }
-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:
 .D1 Li ` Ns Ar command Ns Li `
-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 ma
 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
+.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.
 .Ic trap
 command has no effect on signals that were ignored on entry to the shell.

More information about the svn-src-all mailing list