From owner-svn-src-all@FreeBSD.ORG Sun Mar 20 23:52:45 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 614BD1065670; Sun, 20 Mar 2011 23:52:45 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 49FC48FC0C; Sun, 20 Mar 2011 23:52:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2KNqj58092896; Sun, 20 Mar 2011 23:52:45 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2KNqj9J092894; Sun, 20 Mar 2011 23:52:45 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201103202352.p2KNqj9J092894@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 20 Mar 2011 23:52:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219806 - head/bin/sh X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Mar 2011 23:52:45 -0000 Author: jilles Date: Sun Mar 20 23:52:45 2011 New Revision: 219806 URL: http://svn.freebsd.org/changeset/base/219806 Log: 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 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 .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 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 +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.