I'd like to iterate over a multidimensional json array in bash but haven't found a solution.
Here is what the multidimensional array would look like:
{
"FILES": [
[ "file1.yaml", "file2.yaml", "file3.yaml" ],
[ "file1.json", "file2.json" ]
]
}
I'd like to convert each array into a string that will eventually be the input to a command.
So something like:
#!/bin/bash
Json_Array=$(cat <<EOF
{
"FILES": [
[ "file1.yaml", "file2.yaml", "file3.yaml" ],
[ "file1.json", "file2.json" ]
]
}
EOF
)
function runCmd ()
{
echo "command $1"
}
function runCmds ()
{
jq -c '.FILES' <<< "$Json_Array" | while read i; do
runCmd "$(echo $i | jq .)"
done
}
runCmds
So the output should be:
command file1.yaml file2.yaml file3.yaml
command file1.json file2.json
Thank you for any help!
command
actually be executed in the final script?