SLAX contains a wide variety of operators to enhance script operation. These operators enable the sscript to perform mathematical operations, compare values, convert data and create complex expressions. List below summarizes the available operators in SLAX


Addition
+
var $example = 1 + 1;
Assigns the value of 1 + 1 to the $example variable.

Subtraction,
Negation
-
var $example = 1 - 1;
Assigns the value of 1 - 1 to the $example variable and changes the sign of a number from positive to negative or from negative to positive.

Multiplication
*
<output> 5 * 10;
Results in the value 50 being written to the console.

Division
div
<output> $bit-count div 8;
Divides the bits by eight, returning the byte count, and displays the result on the console (requires that the variable $bit-count has been initialized).

Modulo
mod
<output> 10 mod 3;
Returns the division remainder of two numbers. In this example the expression writes 1 to the console.

Equals
==
$mtu == 1500
If the value assigned to $mtu is 1500 then the expression resolves to true, otherwise it returns false (requires that $mtu has been initialized).

Does not equal
!=
$mtu != 1500
If $mtu equals 1500 then the result is false, otherwise it returns true (requires that $mtu has been initialized)

Less than
<
$hop-count < 15
Returns true if the left value is less than the right value, otherwise it returns false (requires that $hop-count has been initialized).

Less than or equal to
<=
$hop-count <= 14
Returns true if the left value is less than the right value or if the two values are the same, otherwise it returns false (requires that $hop-count has been initialized).

Greater than
>
$hop-count > 0
Returns true if the left value is greater than the right value, otherwise it returns false (requires that $hop-count has been initialized).

Greater than or equal to
>=
$hop-count >= 1
Returns true if the left value is greater than the right value or if they are the same, otherwise it returns false.

Parenthesis
( )
var $result = ( $byte-count * 8 ) + 150;
Used to create complex expressions. Parenthesis function the same way as in a mathematical expression, with the expression within the parenthesis evaluated first. Parenthesis can be nested with the innermost set of parenthesis evaluated first, then the next set, and so on.

And
&&
$byte-count > 500000 && $byte-count < 1000000
The && (and) operator combines two expressions to get one result. If either of the two expressions evaluates to false then the combined expression evaluates to false. 

Or
||
$mtu-size != 1500 || $mtu-size > 2000
The || (or) operator combines two expressions to get one result. If either of the two expressions evaluates to true then the combined expression evaluates to true.

String concatenation
_
var $combined-string = $host-name _ " is located at “ _ $location;
The underscore _ is used to concatenate multiple strings together (note that strings cannot be combined using the + operator in SLAX). In the example if $host-name is “r1” and $location is “HQ” then the value of $combinedstring is “r1 is located at HQ”.

Node-Set Union
|
var $all-interface-nodes = $fe-interface-nodes | $ge-interfacenodes;
The | operator creates a union of two node-sets. All the nodes from one set combine with the nodes in the second set. This is useful when a script needs to perform a similar operation over XML nodes that are pulled from multiple sources.

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

match / {
    <op-script-results> {
        /* Addition */
        <output> 1 + 1;
        
        /* Substraction */
        <output> 1 - 1;
        
        /* Multiplication */
        <output> 5 * 10;
        
        /* Division */
        <output> 10 div 2;
        
        /* Modulo */
        <output> 10 mod 3;
        
        var $mtu = 1500;
        
        /* Equals */
        if ($mtu == 1500) {
            <output> "MTU is 1500";
        }
        
        /* Does not equal */
        if ($mtu != 1400) {
            <output> "Mut is not equal to 1400";
        }
        
        /* Parenthesis */
        <output> ( $mtu * 2 ) + 150;
        
        /* String concatenation */
        <output> "MTU value is " _$mtu;
    }
}