From owner-svn-src-all@FreeBSD.ORG Sat Oct 23 14:04:04 2010 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 7C484106564A; Sat, 23 Oct 2010 14:04:04 +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 505138FC0A; Sat, 23 Oct 2010 14:04:04 +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 o9NE441i088988; Sat, 23 Oct 2010 14:04:04 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9NE440f088986; Sat, 23 Oct 2010 14:04:04 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201010231404.o9NE440f088986@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 23 Oct 2010 14:04:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214242 - stable/7/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: Sat, 23 Oct 2010 14:04:04 -0000 Author: jilles Date: Sat Oct 23 14:04:04 2010 New Revision: 214242 URL: http://svn.freebsd.org/changeset/base/214242 Log: MFC r211621: sh(1): Add a brief summary of arithmetic expressions. Modified: stable/7/bin/sh/sh.1 Directory Properties: stable/7/bin/sh/ (props changed) Modified: stable/7/bin/sh/sh.1 ============================================================================== --- stable/7/bin/sh/sh.1 Sat Oct 23 14:00:31 2010 (r214241) +++ stable/7/bin/sh/sh.1 Sat Oct 23 14:04:04 2010 (r214242) @@ -1142,7 +1142,7 @@ Quote Removal. The .Ql $ character is used to introduce parameter expansion, command -substitution, or arithmetic evaluation. +substitution, or arithmetic expansion. .Ss Tilde Expansion (substituting a user's home directory) A word beginning with an unquoted tilde character .Pq Ql ~ @@ -1357,10 +1357,41 @@ The shell expands all tokens in the .Ar expression for parameter expansion, -command substitution, and quote removal. +command substitution, +arithmetic expansion +and quote removal. +.Pp +The allowed expressions are a subset of C expressions, +summarized below. +.Bl -tag -width "Variables" -offset indent +.It Values +All values are of type +.Ft intmax_t . +.It Constants +Decimal, octal (starting with +.Li 0 ) +and hexadecimal (starting with +.Li 0x ) +integer constants. +.It Variables +Shell variables can be read and written +and contain integer constants. +.It Unary operators +.Li "! ~ + -" +.It Binary operators +.Li "* / % + - << >> < <= > >= == != & ^ | && ||" +.It Assignment operators +.Li "= += -= *= /= %= <<= >>= &= ^= |=" +.It Short-circuit evaluation +The +.Li && +and +.Li || +operators always evaluate both sides. +This is a bug. +.El .Pp -Next, the shell treats this as an arithmetic expression and -substitutes the value of the expression. +The result of the expression is substituted in decimal. .Ss White Space Splitting (Field Splitting) After parameter expansion, command substitution, and arithmetic expansion the shell scans the results of