I have a string that contains a JSON array. Each element of the array is another string. And for each element of the array, I want to end up with an environment variable with a name that is based on that string.
An example might make it clearer. I have this:
json='["foo", "bar", "baz"]'
And I want to end up with these environment variables:
FOO_VAR=1
BAR_VAR=1
BAZ_VAR=1
I guess there are two steps:
- Convert JSON to a bash array
- Walk the bash array, munging each string and setting a variable
I can probably do step 2, but I’m stuck on step 1.