Parameters are variables whose value is assigned by an external source. Other than their declaration they share the same rules as variables, and you can use them in a similar way.

Default Parameters
Every script begins with six parameters predefined, which are declared within junos.xsl. When junos.xsl is imported as part of the standard boilerplate, these parameters are imported as well and can be used within the script.
The default parameters provide commonly-used information for scripts:
  • $product: contains the name of the local Junos device model
  • $user: is assigned to the name of the user that executed the script
  • $hostname: stores the local hostname of the Junos device
  • $script: contains the name of the script that is currently executing
  • $localtime: stores the local time when the script was executed using the following format: Tue Jan 20 14:07:33 2009
  • $localtime-iso: provides a different format of local time: 2009-01-20 14:07:33 PST

Global Parameters
Parameters whose value is set by Junos at script initialization must be defined as global parameters. The default parameters listed above are examples of global parameters. To declare a global parameter, use the param statement and provide a name for the parameter. As with variables, parameter names always require a preceding “$”.
A script can assign a default value to a global parameter. This provides a fallback value in the event that Junos does not give a value to the parameter. If no default value is declared and none is assigned during script processing, then the parameter defaults to an empty string. Here is an example where the $interface parameter defaults to “fxp0”.

$junos-context
In Junos OS Release 11.1 and later, Junos OS also provides a single global variable, $junos-context, which is accessible for use in all commit, op, or event scripts that import the junos.xsl file. The $junos-context variable is a node-set, which has elements that mirror the original global parameters as well as additional elements with information about the Junos OS environment, such as whether a script is executed on the master Routing Engine.

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

/* This is a global parameter with a default value */
param $interface = "fxp0";

match / {
    <op-script-results> {
        /* Output $interface */
        <output> $interface;
    }
}