I have an array in my script which I want to use it in for, like this:
for j in "${list[@]}"
do
func $j
done
In function func, sometimes another member will add to the list array, but the for iterates as many time as it was initiated(before the for started)
I want "for" to iterate based on the updated array content
some lines of that function:
if [ $s1 -gt 0 ]
then
(( k = $k +1 ))
list[$k]=$id2
fi
whileloop to keep the going and track where you are in the list, and possibly have it update the stop condition during iteration$kyou could change the loop until $k instead of the in clause"$j"on the line that passes it tofunc. You don't want the shell treating the contents of the variable as code. (word-splitting on whitespace)