basename

Table of Contents

Prototype: basename(filename, optional_extension)

Return type: string

Description: Retrieves the basename of a filename.

This function implements the same behavior of basename program on Unix and Unix-like operating systems.

Arguments:

  • filename: string, in the range: .*
  • optional_extension: string, in the range: .*

Example:

bundle agent main
{
  vars:
      "basename" -> { "CFE-3196" }
        string => basename( $(this.promise_filename) );

      "basename_wo_extension" -> { "CFE-3196" }
        string => basename( $(this.promise_filename), ".cf" );
  reports:

      "basename = '$(basename)'";
      "basename without '.cf' extension = '$(basename_wo_extension)'";
}
R: basename = 'basename.cf'
R: basename without '.cf' extension = 'basename'

This policy can be found in /var/cfengine/share/doc/examples/basename.cf and downloaded directly from github.

History:

  • Introduced in 3.15.0