A list is a finite sequence of values. These values need not
necessarily have the same data type. List constants are denoted
by square brackets. In contrast to C it is possible to use complex
expressions as list members when defining a list constant. The
empty list is denoted by []
.
Example 2.6. List constants
[ ] [ 1, 2, true ] [ variable, 17 + 38, some_function(x, y) ] [ "list", "of", "strings" ]
Accessing the list elements is done by means of the index operator as
in my_list[1]:"error"
. The list elements are
numbered starting with 0, so index 1 returns the second element.
After the index operator there must be a colon
denoting a following default value that is
returned if the list access fails somehow. The default value should
have the type that is expected for the current list access, in this
case the string “error”.
Note 1: A list preserves order of its elements when iterating over them.
Note 2: There is also another method for accessing lists, originating
from the early days of YaST
. The command select(my_list,
1, "error")
also returns the second element of
my_list
. While this still works, it is deprecated
by now and may be dropped in the future.