From owner-svn-src-all@FreeBSD.ORG Fri Nov 14 17:11:30 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E37AD948; Fri, 14 Nov 2014 17:11:29 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C4B67350; Fri, 14 Nov 2014 17:11:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAEHBTFr044099; Fri, 14 Nov 2014 17:11:29 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAEHBT9m044098; Fri, 14 Nov 2014 17:11:29 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201411141711.sAEHBT9m044098@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Fri, 14 Nov 2014 17:11:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274515 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 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: Fri, 14 Nov 2014 17:11:30 -0000 Author: jilles Date: Fri Nov 14 17:11:28 2014 New Revision: 274515 URL: https://svnweb.freebsd.org/changeset/base/274515 Log: sh(1): Add/improve information about exit status of commands. Modified: head/bin/sh/sh.1 Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Fri Nov 14 16:00:53 2014 (r274514) +++ head/bin/sh/sh.1 Fri Nov 14 17:11:28 2014 (r274515) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd November 7, 2014 +.Dd November 14, 2014 .Dt SH 1 .Os .Sh NAME @@ -795,10 +795,13 @@ should indicate the various exit codes a Additionally, the built-in commands return exit codes, as does an executed shell function. .Pp -If a command is terminated by a signal, its exit status is 128 plus -the signal number. -Signal numbers are defined in the header file -.In sys/signal.h . +If a command is terminated by a signal, its exit status is greater than 128. +The signal name can be found by passing the exit status to +.Li kill -l . +.Pp +If there is no command word, +the exit status is the exit status of the last command substitution executed, +or zero if the command does not contain any command substitutions. .Ss Complex Commands Complex commands are combinations of simple commands with control operators or keywords, together creating a larger complex @@ -818,7 +821,8 @@ function definition .El .Pp Unless otherwise stated, the exit status of a command is -that of the last simple command executed by the command. +that of the last simple command executed by the command, +or zero if no simple command was executed. .Ss Pipelines A pipeline is a sequence of one or more commands separated by the control operator @@ -902,6 +906,8 @@ The format for running a command in back If the shell is not interactive, the standard input of an asynchronous command is set to .Pa /dev/null . +.Pp +The exit status is zero. .Ss Lists (Generally Speaking) A list is a sequence of zero or more commands separated by newlines, semicolons, or ampersands, @@ -940,6 +946,13 @@ command is: .Ic fi .Ed .Pp +The exit status is that of selected +.Ic then +or +.Ic else +list, +or zero if no list was selected. +.Pp The syntax of the .Ic while command is: @@ -960,6 +973,9 @@ in place of which causes it to repeat until the exit status of the first list is zero. .Pp +The exit status is that of the last execution of the second list, +or zero if it was never executed. +.Pp The syntax of the .Ic for command is: @@ -1040,10 +1056,6 @@ continuing until a list terminated with or the end of the .Ic case command. -The exit code of the -.Ic case -command is the exit code of the last command executed in the list or -zero if no patterns were matched. .Ss Grouping Commands Together Commands may be grouped by writing either .Pp @@ -1131,6 +1143,8 @@ and the syntax is: The .Ic local command is implemented as a built-in command. +The exit status is zero +unless the command is not in a function or a variable name is invalid. .Pp When a variable is made local, it inherits the initial value and exported and readonly flags from the variable