5.3 Arithmetic operations
In job definition scripts, a variable value is treated as characters unless it is declared explicitly in the -i option of the typeset command as the integer type. However, if you specify an operator used for an arithmetic operation in the let command or in (()), the values assigned to variables are treated as numeric values during the arithmetic operation.
JP1/Advanced Shell supports arithmetic operators, increment and decrement operators, bitwise logical operators, and assignment operators. The following describes the specifications common to all operators:
-
When you use the let command to perform arithmetic operations, do not place any spaces between a variable and an operator. If there is a space between a variable and an operator, the operation terminates with an error because of invalid format. If you need to place a space between a variable and an operator, either use (( )) (abbreviation of the let command) or enclose the entire arithmetic expression in quotation marks.
Examples
let NUM = 100 - 99 # Terminates with an error because the arithmetic expression is not enclosed in quotation marks let " NUM = 100 - 99 " # Arithmetic expression is executed because it is enclosed in quotations marks (( NUM = 100 - 99 )) # Arithmetic expression is executed because the abbreviation (( )) is used
-
In arithmetic expressions, you can specify variables to which numeric values or numbers are assigned. A base number notation (base-number#value) can be used to specify numeric values.
If the base number notation is omitted, the value is interpreted as a decimal number during operation.
-
If a non-numeric character is assigned to a specified variable, the operation terminates with an error.
- Organization of this section