Syntax: %exp(n,level)

Returns the nth sub-expression value from the previous expression that was evaluated. If no argument is specified, then the value of the entire previous expression is returned (same as n=0).

This is similar to using %pat to return subpatterns, except that this works with any expression enclosed in parenthesis. Parenthesis are used to indicate sub-expressions.

The optional "level" argument can be used to specify the stack level to return results from. If omitted, the default value of 0 is used to access the current stack level. 1 would return subexpressions from the previous stack level, 2 from the stack level above that, etc. This can be used to fetch expressions within nested commands.


#IF ((@a) AND (@b)) {#SHOW %exp %exp(1) %exp(2)}
would display "1 123 999". The "1" is the result of the entire "(@a) AND (@b)" expression, which has a logical value of true. The "123" is the first subexpression (@a) and the "999" is the second subexpression (@b).

NOTE: TeSSH optimized logical expression tests. In the case of AND, once a subexpression evaluates to False (0), then the remaining subexpressions are not evaluated. In the case of OR, once a subexpression evaluates to True (1), then the remaining subexpressions are not evaluated.

So, if the above example was changed to:

#IF ((@a) OR (@b)) {#SHOW %exp %exp(1) %exp(2)}

then the result would be "123 123". Where the first 123 is the result of the entire expression, and the second 123 is the @a subexpression. %exp(2) returns a null value because the (@b) subexpression was never evaluated (it didn't need to be evaluated because a True result was already obtained by the first subexpression)

Add comment

Login or register to post comments