How do I iterate over square brackets type data:
I have written this script:
#!/usr/bin/env bash
# This is a external variable I have in Bash file which has the data already
echo $sample_data_set
for i in "${sample_data_set[@]}"
do
:
echo $i
done
And I need to iterate over $sample_data_set. Am I missing something?
I am getting output:
[ "test1", "test2", "test3", "test4" ]
test.sh: 6: Bad substitution
sample_data_setis supposed to be an array ... trysample_data_set=( test1 test2 test3 test4 ); theforloop should then work correctly (ie, it should printtest1\ntest2\ntest3\ntest4\n[ "foo", "bar", "baz" ]with up to 20 values as a Bash array?", right?-rargument to jq when what you're extracting are strings and you don't want them quoted as JSON.