Hello guys,
I have two attributes like these:
default['cookbook']['array1'] = [ "a", "b", "c", "d" ]
default['cookbook']['array2'] = [ "x", "y", "z", "w" ]
I need to pass these attributes as variables to a template like this:
template "/tmp/some.sh" do
source "some.sh.erb"
owner 'root'
group 'root'
mode "0755"
variables(
:bash_array1 => node['cookbook']['array1'],
:bash_array2 => node['cookbook']['array2']
)
end
In my bash script i need to have two arrays which will have each, the value of the two array above, like this
#!/bin/bash
inputs1=( "a" "b" "c" "d" )
inputs2=( "x" "y" "z" "w" )
Later edit:
If I make the simplest substitution,
#!/bin/bash
inputs1='<% @bash_array1 %>'
The result would be a string like:
inputs1='["a", "b", "c", "d" ]
And I would need to transform it to a bash array with
inputs1=$(echo $inputs | sed "s/\[/( /; s/]/ )/; s/[',]//g")
which would have as a result this:
inputs1=( "a" "b" "c" "d" )
But this is not longer an array, but just a string.
What’s the simpliest way to do it?
Thank you,
Gabriel