"$emails" has the array of values, i want to parse the values from it, To do it, i am using the jq. if i do below command
echo "$emails" | ./jq '.total_rows'
i could get the value i.e 4, i want to store the returned results into some variable,
total_rows="$emails" | ./jq '.total_rows'
but total_rows has no value.
echo $total_rows
How do store the returned result into variable?
You have to use the right quotation, like this:
total_rows=`echo "$emails" | ./jq '.total_rows'`
The `` will execute the command and give total_rows the value of it, so whatever would be the output of
echo "$emails" | ./jq '.total_rows'
will so be stored in total_rows.
As mentioned in the comments by Tom Fenech, it is better to use $() for command substitution. It provides a better readability. So what you can do is:
total_rows=$(echo "$emails" | ./jq '.total_rows')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With