Hi i have this jq output from a CLI command
["test-KEY","test-PASSWORD"]
Assigned that output to a bash variable in this manner
secret_list=`mycli | jq`
I want to iterate though that output in bash & perform another CLI command on each item
so far i tried this block & is not coming desired command execution
echo "secrets_list: "$secrets_list
length=${#secrets_list[@]}
echo "Number of secrets $length"
for secret in "${secrets_list[@]}"
do
echo "$secret"
done
Output is
secrets_list: ["test-KEY","test-PASSWORD"]
Number of secrets 1
["test-KEY","test-PASSWORD"]
my expectation is to iterate through that array. I am not sure what i am doing wrong. Thanks in advance for help
>Solution :
Bash arrays are not JSON arrays and JSON arrays are not bash arrays. If you none of your values contains new lines, you could use read in a loop:
mycli | jq -r '.[]' | while read -r secret; do
echo "$secret"
done