I have an array with some data:
array1=( AAA BBB CCC DDD )
I want to populate an array of results from calling a certain API with the data in array1 and at the same time I want to show the progress with zenity. So I though about doing this:
i=0
prog=0
for c in ${array1[@]}; do
echo $prog #updates the text
echo "# $c" #updates the percentage
data_array[$i]=$(curl -s "https://hub.dummyapis.com/products?noofRecords=4&idStarts=1001&useless=$c" | jq .[$i].id | bc)
(( prog=prog+30 ))
(( i++ ))
done | zenity \
--progress \
--title="Title" \
--text="Text" \
--percentage=0 \
--auto-close \
--auto-kill
The problem is that the data_array remains empty.
On the other hand, it gets populated if I omit the pipe to the zenity command. If I understood correctly, it's because the pipe it's spawning a new subprocess, thus the data_array is empty there.
I also tried using this sintax, but with same results:
zenity \
--progress \
--title="Title" \
--text="Text" \
--percentage=0 \
--auto-close \
--auto-kill < <(
for c in ${array1[@]}; do
echo $prog
echo "# $c"
data_array[$i]=$(curl -s "https://hub.dummyapis.com/products?noofRecords=4&idStarts=1001&useless=$c" | jq .[$i].id | bc)
(( prog=prog+30 ))
(( i++ ))
done)
What can I do?
something | while read stuff; do set some vars; done, but not this one.