Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

readenvfile

Suggest changes
Table of contents

Prototype:readenvfile(filename, optional_maxbytes)

Return type:data

Description:Parses key-value pairs from the filefilename in env file format (man os-release).Returns the result as adata variable.Keys and values are interpreted as strings.maxbytes is optional, if specified, only the firstmaxbytes bytes are read fromfilename.Details of the os-release/env file format on freedesktop.org

Arguments:

  • filename:string - File name - in the range:"?(/.*)
  • otpional_maxbytes:int - Maximum number of bytes to read - in the range:0,99999999999

Syntax example:

code
vars:"loadthis"data=>readenvfile("/etc/os-release");

Complete example:

Prepare:

code
echo 'PRETTY_NAME="Ubuntu 14.04.5 LTS"' > /tmp/os-release

Run:

code
bodyedit_defaultsempty{empty_file_before_editing=>"true";edit_backup=>"false";}bundleedit_lineinsert_lines(lines){insert_lines:"$(lines)";}bodyprintfilecat(file){file_to_print=>"$(file)";number_of_lines=>"inf";}bundleagentmain{classes:"file_found"expression=>fileexists("/tmp/os-release");# Use readenvfile() to load /tmp/os-release, then convert to json:vars:file_found::"envdata"data=>readenvfile("/tmp/os-release");"jsonstring"string=>storejson(envdata);# Print input(os-release) and output(json) files:reports:file_found::"/tmp/os-release :"printfile=>cat("/tmp/os-release");"/tmp/os-release converted to json:";"$(jsonstring)";"(The data for this system is available in sys.os_release)";!file_found::"/tmp/os-release doesn't exist, run this command:";"echo 'PRETTY_NAME=\"Ubuntu 14.04.5 LTS\"' > /tmp/os-release";}

Output:

code
R: /tmp/os-release :R: PRETTY_NAME="Ubuntu 14.04.5 LTS"R: /tmp/os-release converted to json:R: {  "PRETTY_NAME": "Ubuntu 14.04.5 LTS"}R: (The data for this system is available in sys.os_release)

Notes:This function is used internally to load/etc/os-release intosys.os_release.

See also:data_expand(),readdata(),parsejson(),parseyaml(),storejson(),mergedata(), anddata documentation.

History:

  • Introduced in 3.11.0

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp