isvariable

Table of Contents

Prototype: isvariable(var)

Return type: boolean

Description: Returns whether a variable named var is defined.

The variable need only exist. This says nothing about its value. Use regcmp to check variable values. Variable references like foo[bar] are also checked, so this is a way to check if a classic CFEngine array or a data container has a specific key or element.

Arguments:

  • var: string - Variable identifier - in the range: .*

Example:

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

bundle agent example
{
  vars:

      "bla" string => "xyz..";

  classes:

      "exists" expression => isvariable("bla");

  reports:

    exists::

      "Variable exists: \"$(bla)\"..";

}

Output:

R: Variable exists: "xyz.."..