|
|
Line 1,020: |
Line 1,020: |
|
| |
|
| == ARITHMETIC EVALUATION == | | == ARITHMETIC EVALUATION == |
| The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let
| | シェルでは、特定の条件下で算術式を評価することができる(letおよびdeclare組み込みコマンド、(( 複合コマンド、算術展開参照)。 評価は固定幅の整数で行われ、オーバーフローのチェックは行われないが、0による除算はトラップされ、エラーとしてフラグが立てられる。 演算子とその優先順位、連想順位、値はC言語と同じである。 以下の演算子のリストは、等しい優先順位の演算子のレベルにグループ化されている。 レベルは優先順位の低い順に並んでいる。 |
| and declare builtin commands, the (( compound command, and Arithmetic Expansion). Evaluation is
| |
| done in fixed-width integers with no check for overflow, though division by 0 is trapped and
| |
| flagged as an error. The operators and their precedence, associativity, and values are the same
| |
| as in the C language. The following list of operators is grouped into levels of equal-precedence
| |
| operators. The levels are listed in order of decreasing precedence.
| |
|
| |
|
| id++ id-- | | id++ id-- |
Line 1,052: |
Line 1,047: |
| comma | | comma |
|
| |
|
| Shell variables are allowed as operands; parameter expansion is performed before the expression
| | 式が評価される前にパラメータ展開が行われる。 式中では、パラメータ展開構文を使わずにシェル変数を名前で参照することもできる。 NULLまたは未設定のシェル変数は、パラメータ展開構文を使わずに名前で参照すると0と評価される。 変数の値は、その変数が参照されたとき、または declare -i を使って整数属性を与えられた変数に値が割り当てられたときに、算術式として評価される。 シェル変数は、式で使用するために整数属性をオンにする必要はない。 |
| is evaluated. Within an expression, shell variables may also be referenced by name without using
| |
| the parameter expansion syntax. A shell variable that is null or unset evaluates to 0 when ref‐
| |
| erenced by name without using the parameter expansion syntax. The value of a variable is evalu‐
| |
| ated as an arithmetic expression when it is referenced, or when a variable which has been given
| |
| the integer attribute using declare -i is assigned a value. A null value evaluates to 0. A
| |
| shell variable need not have its integer attribute turned on to be used in an expression.
| |
|
| |
|
| Integer constants follow the C language definition, without suffixes or character constants.
| | 整数定数はC言語の定義に従うが、接尾辞や文字定数は付けない。 |
| Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadec‐
| | 先頭に0を持つ定数は、8進数として解釈される。 先頭の0xまたは0Xは16進数を表す。 それ以外の場合、数値は<nowiki>[base#]n</nowiki>の形をとる。オプションのbaseは算術基底を表す2から64までの10進数で、nはその基底の数値である。 base#が省略された場合は、10進数が使用される。 nを指定する際、数字以外が必要な場合は、9より大きい数字を小文字、大文字、@、_の順で表す。 |
| imal. Otherwise, numbers take the form [base#]n, where the optional base is a decimal number be‐
| | 基数が36以下の場合、小文字と大文字を入れ替えて10以上35以下の数字を表すことができる。 |
| tween 2 and 64 representing the arithmetic base, and n is a number in that base. If base# is
| |
| omitted, then base 10 is used. When specifying n, if a non-digit is required, the digits greater
| |
| than 9 are represented by the lowercase letters, the uppercase letters, @, and _, in that order.
| |
| If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably
| |
| to represent numbers between 10 and 35.
| |
|
| |
|
| Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated
| | 演算子は優先順位の高い順に評価される。 括弧内の部分式は最初に評価され、上記の優先順位の規則を上書きすることができる。 |
| first and may override the precedence rules above.
| |
|
| |
|
| == CONDITIONAL EXPRESSIONS == | | == CONDITIONAL EXPRESSIONS == |