Eval
3.2.8 Eval
Eval - Define a script variable where the value is evaluated as a numeric expression. See the Numeric Expressions chapter of this manual for more info. The behaviour is otherwise exactly the same as the Var command.
SYNOPSIS
eval <var_name_1>=<numeric_expression_1> \[<var_name_2>=<numeric_expression_2> ... <var_name_N>=<numeric_expression_N>\]
* Red colour indicates obligatory parameters
OPTIONS
var_name
- A name for the variable. The name is case sensitive and must not contain spaces.
numeric_expression
- A numeric expression or a string which results in a numeric expression after all variable calls located in the argument are resolved. If it contains spaces it must be enclosed in double-quotes, e.g. "1 + 1". See the Numeric Expressions chapter of this manual for more info on expression syntax and supported numeric operators.
RETURNS
The Eval command in always returns 0 (zero) up to version 2.3.2. Version 2.3.3 and newer return 0 if the numeric expression was evaluated correctly or a value other than 0 if the expression could not be evaluated, for example when it contains the call of a variable which doesn't exist. This mechanism allows testing of whether the value was populated correctly and branch the code through the if/else statement checking the _EXIT_CODE variable value.
EXAMPLES
Eval POSITION=2*(10+1)
- Create a variable POSITION with a value of 22.
Eval SUM={SUM}+10
if ({_EXIT_CODE} != 0) {
Exit
1
}
- Increase the existing variable of SUM by 10. If the variable doesn't exist the script will terminate with the exit code of 1.
Var A=1
B=2
C=3
// As Var resolves the variable calls and concatenates
// the strings the ABC1 value will be a string of "123+1".
Var ABC1="{A}{B}{C}+1"
// As Eval resolves the variable calls and evaluates the result
// as a numeric expression the ABC2 value will be "124".
Eval ABC2="{A}{B}{C}+1"
- This example demonstrates the difference between how the Var and Eval commands construct the variable value.