Prototype: join(glue, list)

Return type: string

Description: Join the items of list into a string, using the conjunction in glue.

Converts a list or data container into a scalar variable using the join string in first argument.

This function can accept many types of data parameters.

Arguments:

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

Example:

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

bundle agent test
{
  vars:
    "mylist" slist => { "one", "two", "three", "four", "five" };

    "datalist"
      data => parsejson(
        '[1,2,3,
                        "one", "two", "three",
                        "long string",
                        "four", "fix", "six",
                        "one", "two", "three",]'
      );

    "mylist_str" string => format("%S", mylist);
    "datalist_str" string => format("%S", datalist);
    "myscalar" string => join("->", mylist);
    "datascalar" string => join("->", datalist);

  reports:
    "Concatenated $(mylist_str): $(myscalar)";
    "Concatenated $(datalist_str): $(datascalar)";
}
R: Concatenated { "one", "two", "three", "four", "five" }: one->two->three->four->five
R: Concatenated [1,2,3,"one","two","three","long string","four","fix","six","one","two","three"]: 1->2->3->one->two->three->long string->four->fix->six->one->two->three

Output:

R: Concatenated { "one", "two", "three", "four", "five" }: one->two->three->four->five
R: Concatenated [1,2,3,"one","two","three","long string","four","fix","six","one","two","three"]: 1->2->3->one->two->three->long string->four->fix->six->one->two->three

History: The collecting function behavior was added in 3.9.

See also: string_split(), about collecting functions.