Passing databag value with special characters to powershell block

I have a value in a databag with a special character in it (a dollar $ sign). In my default.rb file I’m getting the value

string = data_bag_item(‘strings’, ‘mystring’)[‘value’]

Then later in my recipe I have the following:

powershell_script ‘script’ do
code <<-EOH
write-host " ‘#{string}’ "

If my string was some$tring what I end up seeing is “some”

It seems like ruby is treating $tring as a global variable. How do I avoid that? I tried to escape the value in my databag using some$string but then its not valid JSON.

How can I work around this?


A am not sure about powershell but usually double quotes mean that string interpolation is possible and single quotes mean its not. So in your case write-host "'#{string}'" would be quite different from write-host '"#{string}"'. Do you need the double quotes at all.