Technical data
8. Documentation for Developers
associated with this array. The control variable takes the values of the respective array
variables. It should be noted that when processing optional array variables that are not
present in the configuration, an empty element is generated. You may have to take this
into account in the script, for example like this:
foreach i in template_var_opt_%
do
if (i != "")
then
warning "%i is present (%i='$i')"
else
warning "%i is undefined (empty)"
fi
done
As you also can see in the example, the name of the respective array variables can be
determined with the %<control variable> construction.
The instruction in the loop may be one of the above control elements or functions (if,
foreach, provides, depends, . . . ).
If you want to access exactly one element of an array, you can address it using the syntax
<Array>[<Index>]. The index can be a normal variable, a numeric constant or again
an indexed array.
2. Iteration over N-variables:
foreach <control variable> in <N-variable>
do
<instruction>
done
This loop executes from 1 to the value that is given in the N-variable. You can use the
control variable to index array variables. So if you want to iterate over not only one but
more array variables at the same time all controlled by the same N-variable you take
this variant of the loop and use the control variable for indexing multiple array variables.
Example:
foreach i in host_n
do
set name=host_%_name[i]
set ip4=host_%_ip4[i]
warning "$i: name=$name ip4=$ip4"
done
The resulting content of the HOST_%_NAME- and HOST_%_IP4-arrays for this example:
Warning: 1: name=berry ip4=192.168.11.226
Warning: 2: name=fence ip4=192.168.11.254
Warning: 3: name=sandbox ip4=192.168.12.254
310










