mvar
Syntax
mvar $name[=initial-value];
Description
Declare a mutable variable in a SLAX script. You can initialize a mutable variable when you declare it by following the variable name with an equal sign (=) and a value.
Mutable variables differ from variables declared using the var
statement in that you can change the value of a
mutable variable after it is declared. To initialize or set the value
of a mutable variable after you declare it, use the set
statement. To append a value to the node set contained in a mutable
variable, use the append
statement.
Mutable variables use non-standard SLAX specific extension elements, which can affect the portability of a script.
Attributes
name |
Mutable variable identifier. After declaration, you can reference the variable within expressions by using the identifier prefixed with the dollar sign ($) character. |
initial-value |
Initial value assigned to the mutable variable. |
SLAX Example
The following example creates the mutable variable block
, and initializes it. The set
statement assigns a new value to the block
variable, overwriting the initial value set in the declaration.
In the for
loop, the code iterates over
each item in the specified list and appends an <item>
element with two child elements, <name>
and <size>
, to the node set stored
in the block
variable.
mvar $block= <block> "start here"; set $block = <block> "item list"; for $item (list) { append $block += <item> { <name> $item/name; <size> $item/size; } }
Release Information
Statement introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.