This page describes the language used for expressions by the eval command.
The following data types are supported:
Data Type |
Description |
string |
All expression values are stored as strings and can be treated as strings. Strings are denoted by either single or double quotes. |
number |
A value can be treated as a number if it contains a valid real or integer number. |
boolean |
All values can be treated as booleans. An empty string or a numeric value of zero are taken to be false, all other values are true. |
The following operators are supported:
Operators |
Description |
* / % |
Standard arithmetic binary operators. The operands must be numbers. |
&& || |
Boolean AND and OR operators - the operands may be of any type but will be treated as booleans. Note there is no NOT operator - see the not() function. |
. |
String concatenation - operands may be of any type but will be treated as strings. |
== <> |
Comparison operators - the operands may be of any type. If both operands can be interpreted as numbers then numeric comparison is performed, otherwise a lexical comparison is used. |
The following functions are available. Function names are case insensitive.
Function |
Description |
abs(num) |
Returns absolute value of num, which must be numeric. |
bool(val) |
Converts val to the boolean values 1 (true) or 0 (false) |
env(name) |
Returns the value of the named environment variable, or an empty string if no such variable exists. |
if(test,v1,v2) |
Evaluates the expression test (which itself may consist of expressions and functions) as a boolean value - if the evaluation is true returns the result of evaluating the expression v1, else it returns the result of evaluating v2. |
int(num) |
Returns the integer part of num, which must be numeric. |
isempty(str) |
Returns true if the string str contains only whitespace or is the empty string, returns false otherwise. |
isnum(str) |
Tests if str is a valid number (either integer or real) |
len(str) |
Return length of string. |
lower(str) |
Returns the string sstr converted to lower-case. |
match(str,regex) |
Returns true if str matches regular expression. |
not(bool) |
Inverts the boolean sense of bool, which may be of any type. |
pos(s1,s2) |
Returns the 1-based position of the string s2 in s1, or zero if s1 does not contain s2. |
random() |
Returns random real number in the range 0.0 <= N < 1.0 |
sign(num) |
Returns the sign of num. Negative numbers return -1, positive numbers 1, zero returns 0. |
streq(s1,s2) |
Returns true if string s1 is identical to s2, ignoring case differences. |
substr(s,start,n) |
Returns a substring of s starting at start and consisting of a maximum of n characters. |
trim(str) |
Returns the string str trimmed of leading and trailing whitespace. |
upper(str) |
Returns the string str converted to upper-case. |
The following read-only variables are set before a function is evaluated:. Variable names are case-insensitive.
Variables |
Description |
$1 $2 ... $N |
Values of the fields in the current CSV input row. If a field variable is used that represents a field that does not exist in the input row, it evaluates as the empty string. |
$fields |
The number of fields in the current input row. |
$file |
The name of the current input file. |
$line |
Line number of the current input line in the current file. |
Created with the Personal Edition of HelpNDoc: Free help authoring environment