Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


expr command (evaluates an expression)

Organization of this page

Format

expr expression

Description

This command evaluates an expression and sends the results to the standard output. All elements of the expression are specified as separate arguments.

An expression is specified as a combination of numeric values, character strings, variables, expressions, and their operators. The evaluation of the expression is retained as a character string or integer.

Arguments

expression

Specifies the expression to be evaluated. The operators are shown below in increasing order of priority. Operators shown enclosed in curly brackets ({}) and separated by the comma have the same priority. When an argument is invalid, the expr command outputs an error message and returns 2 as the return code. Expressions are denoted by expr1 and expr2.

expr1| expr2

If expr1 is not an empty character string or zero, the evaluation of expr1 is returned. If expr1 is an empty character string or zero, the evaluation of expr2 is returned. If expr2 is also a null character string, the null character string is returned.

expr1 & expr2

If neither expression evaluates to an empty character string or zero, the evaluation of expr1 is returned; otherwise, 0 is returned.

expr1 {=, >, >=, <, <=, !=} expr2

If both expressions evaluate to an integer, the result of comparing the integers is returned; otherwise, the result of comparing the character strings in the collating sequence defined locally is returned. The result is 1 if the specified relationship is true, and 0 if it is false.

  • =: The values on the left and right are equal.

  • >: The value on the left is greater than the value on the right.

  • >=: The value on the left is greater than or equal to the value on the right.

  • <: The value on the left is less than the value on the right.

  • <=: The value on the left is less than or equal to the value on the right.

  • !=: The values on the left and right are not equal.

expr1 {+, -} expr2

If both expressions evaluate to integer values, the result of the addition or subtraction is returned.

If the value is not an integer, an error message (expr: non-numeric argument) is output.

  • +: Add

  • -: Subtract

expr1 {*, /, %} expr2

If both expressions evaluate to integer values, the result of the multiplication, division, or modulo operation is returned. If the values are not integers, an error message (expr: non-numeric argument) is output. If the divisor is zero, an error message (expr: division by zero) is output.

  • *: Multiply

  • /: Divide

  • %: Modulo

expr1 : expr2

Evaluates whether expr2 matches expr1.

The expression expr2 is specified as a regular expression. The regular expression is treated as if ^ were added at the beginning of the string.

  • If a tagged regular expression is specified in expr2 (if expr2 matches expr1), the first character string that matched the tagged regular expression is returned.

  • If a tagged regular expression is not specified in expr2 (if expr2 matches expr1), the number of matched characters is returned.

  • If expr2 does not match expr1, and a regular expression is used in expr2, the null character is returned. If a regular expression is not used in expr2, 0 is returned.

  • If the specification of expr2 matches the null character, 0 is returned. To determine if expr1 is the null character, you must evaluate it by assigning the same character to both expr1 and expr2. That is, instead of expr '' : '$', you must use expr X'' : 'X$', or a similar variation.

length character-string

Returns the length of the specified character string. For details about the ADSH_CMDEXPR_LENGTH environment variable, see 2.5 Specifying environment variables.

  • If the ADSH_CMDEXPR_LENGTH=b environment variable is set, the command treats length as an operator and returns the length (in bytes) of the character string that follows.

  • If the ADSH_CMDEXPR_LENGTH=c environment variable is set, the command treats length as an operator and returns the length (in characters) of the character string that follows.

  • If the ADSH_CMDEXPR_LENGTH environment variable is not set or a value other than b or c is set in the environment variable, the command does not treat length as an operator.

You can specify an expression in the length operator. If you specify an expression, enclose the entire expression is parentheses (()).

Return codes

Return code

Meaning

0

Normal termination. The expression is not an empty character string or 0.

1

Normal termination. The expression is an empty character string or 0.

2

Error termination. The expression is not valid.

3 or greater

Error termination

  • An error, such as a memory shortage, occurred.

Notes

Usage examples