From owner-svn-src-all@FreeBSD.ORG Sun Jul 10 15:02:26 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 EB054106564A; Sun, 10 Jul 2011 15:02:25 +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 D17AD8FC08; Sun, 10 Jul 2011 15:02:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p6AF2PVq050690; Sun, 10 Jul 2011 15:02:25 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p6AF2PUA050688; Sun, 10 Jul 2011 15:02:25 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201107101502.p6AF2PUA050688@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 10 Jul 2011 15:02:25 +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: r223909 - 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, 10 Jul 2011 15:02:26 -0000 Author: jilles Date: Sun Jul 10 15:02:25 2011 New Revision: 223909 URL: http://svn.freebsd.org/changeset/base/223909 Log: sh(1): Extend documentation about subshells. Because sh executes commands in subshell environments without forking in more and more cases (particularly from 8.0 on), it makes sense to describe subshell environments more precisely using ideas from POSIX, together with some FreeBSD-specific items. In particular, the hash and times builtins may not behave as if their state is copied for a subshell environment while leaving the parent shell environment unchanged. Modified: head/bin/sh/sh.1 Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Sun Jul 10 15:01:14 2011 (r223908) +++ head/bin/sh/sh.1 Sun Jul 10 15:02:25 2011 (r223909) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd June 24, 2011 +.Dd July 10, 2011 .Dt SH 1 .Os .Sh NAME @@ -861,7 +861,9 @@ causes asynchronous execution of the pre .Ss Background Commands (&) If a command is terminated by the control operator ampersand .Pq Ql & , -the shell executes the command asynchronously; +the shell executes the command in a subshell environment (see +.Sx Grouping Commands Together +below) and asynchronously; the shell does not wait for the command to finish before executing the next command. .Pp @@ -1024,7 +1026,41 @@ or .D1 Li { Ar list Ns Li \&; } .Pp The first form executes the commands in a subshell environment. -Note that built-in commands thus executed do not affect the current shell. +A subshell environment has its own copy of: +.Pp +.Bl -enum +.It +The current working directory as set by +.Ic cd . +.It +The file creation mask as set by +.Ic umask . +.It +References to open files. +.It +Traps as set by +.Ic trap . +.It +Known jobs. +.It +Positional parameters and variables. +.It +Shell options. +.It +Shell functions. +.It +Shell aliases. +.El +.Pp +These are copied from the parent shell environment, +except that trapped (but not ignored) signals are reset to the default action +and known jobs are cleared. +Any changes do not affect the parent shell environment. +.Pp +A subshell environment may be implemented as a child process or differently. +If job control is enabled in an interactive shell, +commands grouped in parentheses can be suspended and continued as a unit. +.Pp The second form never forks another shell, so it is slightly more efficient. Grouping commands together this way allows the user to @@ -1552,10 +1588,12 @@ The command is executed in a subshell en except that the built-in commands .Ic jobid , .Ic jobs , -.Ic times and .Ic trap -return information about the main shell environment +return information about the parent shell environment +and +.Ic times +returns information about the same process if they are the only command in a command substitution. .Ss Arithmetic Expansion Arithmetic expansion provides a mechanism for evaluating an arithmetic @@ -2359,8 +2397,8 @@ If there are zero positional parameters, A built-in equivalent of .Xr test 1 . .It Ic times -Print the amount of time spent executing the shell and its children. -The first output line shows the user and system times for the shell +Print the amount of time spent executing the shell process and its children. +The first output line shows the user and system times for the shell process itself, the second one contains the user and system times for the children. .It Ic trap Oo Ar action Oc Ar signal ... @@ -2386,7 +2424,7 @@ Omitting the .Ar action is another way to request the default action, for compatibility reasons this usage is not recommended though. -In a subshell environment, +In a subshell or utility environment, the shell resets trapped (but not ignored) signals to the default action. The .Ic trap