Bernhard-

It would help if I understood better what you are trying to accomplish with the 
array... but a few things:

1) Look at section 11.1.2 at 
http://www.cfengine.org/manuals/cf3-reference.html#Introduction-to-functions 
for building array's from data
2) The error you're getting on this line
        "string[$(myarray)] string => execresult("/bin/egrep \"mypatter\" 
/localhost/somelocation/$(myarray) | cut ...", "noshell")
may be for a few reasons.  1) missing close quote on variable name, or 2) 
$(myarray)" is not defined, and thus when you reference it you get the string 
"$(myarray)", which is as you say, illegal.

Can you say, in words, what you want to do?  Does something like 
readstringarray() do what you want?

-Dan

On Sep 23, 2010, at 6:33 AM, no-re...@cfengine.com wrote:

> Forum: Cfengine Help
> Subject: dynamic variable declaration
> Author: bglomm
> Link to topic: https://cfengine.com/forum/read.php?3,18441,18441#msg-18441
> 
> hi all,
> 
> Could anybody give me a hint on how to construct variable names during 
> runtime (amount and names shall come from a "ls" command on a specific 
> directory) and fill each of this variables with a value extracted from the 
> corresponding file?
> 
> 
> What I tried: 
> 
> In /localhost/somelocation/
> there are a bunch of files, let's say: test1, test2, othertest3 (arbitrary 
> unknown names).
> each of this files contains a tagged line that I can get with egrep... and 
> extract with a simple cut...
> Now I like to build an array of the form:
> myarray string => "extracted-value-from-file-test1"
> myarray string => "extracted-value-from-file-test2"
> myarray string => "extracted-value-from-file-othertest3"
> 
> in the "var:" section I can do a
> 
> "allfiles" string => execresult("/bin/ls -x /localhost/somelocation/", 
> "noshell");
> "allfiles_array" slist => splitstring("$allfiles)", "\W", "20");
> ... so far all fine and works, but now I would need something like:
> 
> "string[$(myarray)] string => execresult("/bin/egrep \"mypatter\" 
> /localhost/somelocation/$(myarray) | cut ...", "noshell")
> 
> but that doesn't work (Variable identifier contains illegal character, i.e. 
> the $ ...)
> 
> TIA
> 
> Bernhard
> 
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to