1#+begin_src prep 2#@ ``` 3#@ printf "one\ntwo\nthree\n" > /tmp/list.txt 4#@ printf " # commented line\n" >> /tmp/list.txt 5#@ printf "1\n2\n3\n" >> /tmp/list.txt 6#@ printf "# another commented line\n" >> /tmp/list.txt 7#@ printf "Not a commented # line\n" >> /tmp/list.txt 8#@ printf "1.0\n2.0\n3.0" >> /tmp/list.txt 9#@ ``` 10#+end_src 11#+begin_src cfengine3 12bundle agent example_readstringlist 13# @brief Example showing readstringlist() 14{ 15 vars: 16 "my_list_of_strings" 17 slist => readstringlist( "/tmp/list.txt", # File to read 18 "^\s*#[^\n]*", # Exclude hash comment lines lines 19 "\n", # Split on newlines 20 inf, # Maximum number of entries 21 inf); # Maximum number of bytes to read 22 23 reports: 24 "my_list_of_strings includes '$(my_list_of_strings)'"; 25} 26bundle agent __main__ 27{ 28 methods: "example_readstringlist"; 29} 30#+end_src 31#+begin_src example_output 32#@ ``` 33#@ R: my_list_of_strings includes 'one' 34#@ R: my_list_of_strings includes 'two' 35#@ R: my_list_of_strings includes 'three' 36#@ R: my_list_of_strings includes '1' 37#@ R: my_list_of_strings includes '2' 38#@ R: my_list_of_strings includes '3' 39#@ R: my_list_of_strings includes 'Not a commented # line' 40#@ R: my_list_of_strings includes '1.0' 41#@ R: my_list_of_strings includes '2.0' 42#@ R: my_list_of_strings includes '3.0' 43#@ ``` 44#+end_src 45