Reputation: 6394
I am trying to pass values from a ruby hash to a bash script.. What would be the best way to do it? The size and key/value pairs in ruby are always different..
so if I want something like..
hsh = {"key1"=>"value1", "key2"=>"value2"}
%x[sh script.sh #{hsh}]
What would I need on the bash side?
EDIT: If the hash on ruby side won't work, I can use another data structure, what I care about is that the size of the container (hash/ array) will be always different..
EDIT2: By "care about the size" I mean that the hash/ array will have different number of elements every time.. . sorry for unclarity
Upvotes: 1
Views: 1147
Reputation: 360665
You can print the values from the Ruby script and read them in the Bash script. You will need Bash 4 in order to use associative arrays or you can iterate over the values and act on them as they're read. Why not do what you want to do in Bash within the Ruby script instead?
# works with Bash 3 or 4
while read -r key value
do
echo "$key $value" # act on the keys and values
done < <(ruby-script)
Upvotes: 1