Table of Contents
const
Table of Contents
CFEngine defines a number of variables for embedding unprintable values or values with special meanings in strings.
bundle agent __main__
{
vars:
"example_file"
string => "/tmp/const-vars.txt";
files:
"$(example_file)"
create => "true",
content => concat("CFEngine const vars$(const.n)",
"before const.at $(const.at) after const.at$(const.n)",
"before const.dollar $(const.dollar) after const.dollar$(const.n)",
"before const.dirsep $(const.dirsep) after const.dirsep$(const.n)",
"before const.endl$(const.endl) after const.endl$(const.n)",
"before const.n$(const.n) after const.n$(const.n)",
"before const.r $(const.r) after const.r$(const.n)",
"before const.t $(const.t) after const.t$(const.n)");
reports:
"const vars available: $(with)"
with => storejson( variablesmatching_as_data( "default:const\..*" ) );
"$(example_file):"
printfile => cat( "$(example_file)" );
}
body printfile cat(file)
{
file_to_print => "$(file)";
number_of_lines => "inf";
}
R: const vars available: {
"default:const.at": "@",
"default:const.dirsep": "/",
"default:const.dollar": "$",
"default:const.endl": "\n",
"default:const.n": "\n",
"default:const.r": "\r",
"default:const.t": "\t"
}
R: /tmp/const-vars.txt:
R: CFEngine const vars
R: before const.at @ after const.at
R: before const.dollar $ after const.dollar
R: before const.dirsep / after const.dirsep
R: before const.endl
R: after const.endl
R: before const.n
R: after const.n
R: before const.r
```cf3
after const.r
R: before const.t after const.t ```
This policy can be found in
/var/cfengine/share/doc/examples/const.cf
and downloaded directly from
github.
const.at
reports:
"The value of $(const.at) is @";
History:
- Added in CFEngine 3.19.0, 3.18.1
const.dollar
reports:
# This will report: The value of $(const.dollar) is $
"The value of $(const.dollar)(const.dollar) is $(const.dollar)";
# This will report: But the value of $(dollar) is $(dollar)
"But the value of $(dollar) is $(dollar)";
const.dirsep
reports:
# On Unix hosts this will report: The value of $(const.dirsep) is /
# On Windows hosts this will report: The value of $(const.dirsep) is \\
"The value of $(const.dollar)(const.dirsep) is $(const.dirsep)";
const.endl
reports:
"A newline with either $(const.n) or with $(const.endl) is ok";
"But a string with \n in it does not have a newline!";
const.n
reports:
"A newline with either $(const.n) or with $(const.endl) is ok";
"But a string with \n in it does not have a newline!";
const.r
reports:
"A carriage return character is $(const.r)";
const.t
reports:
"A report with a$(const.t)tab in it";