The SLAX scripting language has a set of basic syntax rules. Since Junos scripts contain XML elements and data structures, scripts must follow these relevant formatting rules.
The rest of the SLAX syntax rules are very similar to the Junos configuration syntax rules. For example, code blocks and line termination within SLAX scripts are done in the same manner as in Junos configuration, and the formatting of strings and comments in SLAX is also comparable to Junos.


Code Blocks:

A Junos configuration indicates hierarchy through the use of curly braces { }:
interfaces { 
    interface ge-0/0/0 { 
        disable; 
    }
}
In the above example, the interfaces configuration hierarchy contains the interface ge-0/0/0 hierarchy, which contains disable.

The SLAX scripting language follows a similar style, enclosing distinct code blocks within curly braces to indicate their hierarchy and bounds. Review this portion of the configuration from the Hello World script:
match { 
    <op-script-results> { 
        <output> "Hello World!";
    }
}
Curly braces bound the match / code block. This provides a clear boundary indicating exactly where the code block starts, where it stops, and what code it contains.

Line termination:

SLAX terminates individual statements with a semi-colon (the same as in Junos configuration). The semi-colon tells the script engine in Junos that the end of the statement has been reached. For example:
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";

String values:

A string is a sequence of text characters. "Hello World!" is an example of string in Hello world script. Scripts must always enclose string values within quotes. SLAX allows the use of either single quotes ‘String Value’ or double quotes “String Value”, but the character used to open the string must also be used to close it.

Comments:

Comments in SLAX scripts are written within the delimiters /* and */ such as:
/* This is a comment. */


Edit the script to the right and run it to test your understanding of SLAX syntax rules.

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";

match / {
    <op-script-results> {
        /* Display this string on the console */
        <output> "Hello World!";
    }
}