Prototype: unique(list)

Return type: slist

Description: Returns list of unique elements from list.

This function can accept many types of data parameters.

Arguments:

  • list: string - CFEngine variable identifier or inline JSON - in the range: .*

Example:

code
body common control
{
      bundlesequence => { "test" };
}

bundle agent test
{
  vars:
      "test" slist => {
                        1,2,3,
                        "one", "two", "three",
                        "long string",
                        "four", "fix", "six",
                        "one", "two", "three",
      };

      "test_str" string => join(",", "test");
      "test_unique" slist => unique("test");
      "unique_str" string => join(",", "test_unique");

  reports:
      "The test list is $(test_str)";
      "The unique elements of the test list: $(unique_str)";
}

Output:

code
R: The test list is 1,2,3,one,two,three,long string,four,fix,six,one,two,three
R: The unique elements of the test list: 1,2,3,one,two,three,long string,four,fix,six

History: The collecting function behavior was added in 3.9.

See also: filter(), about collecting functions, and data documentation.