I have JSON
in a file nomes.txt
.
JSON
is:
{"p": { "nome": ["josé","Maria", "carlos","Artur"] }}
I want to throw the query value of it into a variable.
Show the results:
#!/bin/bash
ns='cat nomes.txt'
echo $ns
for ((i=0; i<=4; i++))
do
echo $ns | jq -r ".p | .nome[$i]"
done
But when I try to do something more elaborate I can not.
I want to play the value of the JSON
caught in the variable but it will not.
#!/bin/bash
ns='cat nomes.txt'
echo $ns
for ((i=0; i<=4; i++))
do
aux=$ns | jq -r ".p | .nome[$i]"
echo "O nome $i é $aux"
done
The value for $aux
is null.
How can I transfer the value to the aux
variable?