diff options
author | jilles <jilles@FreeBSD.org> | 2010-08-22 13:04:00 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-08-22 13:04:00 +0000 |
commit | b23d3a5ce5dae3490e3a830279dbb6a158b70af9 (patch) | |
tree | 14285d8d65947047e4c699092c1af2e6626f79a3 | |
parent | 50c197f6b9d5dd3e49d2a2a2df52f1a7b82a4cc5 (diff) | |
download | FreeBSD-src-b23d3a5ce5dae3490e3a830279dbb6a158b70af9.zip FreeBSD-src-b23d3a5ce5dae3490e3a830279dbb6a158b70af9.tar.gz |
sh(1): Add a brief summary of arithmetic expressions.
-rw-r--r-- | bin/sh/sh.1 | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 1498564..ff89125 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd June 29, 2010 +.Dd August 22, 2010 .Dt SH 1 .Os .Sh NAME @@ -1230,7 +1230,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 ~ @@ -1463,10 +1463,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 |