Hi,
I'm trying to update variable's value in a piped loop:
Code:
a=0
txt='a\nb\nc'
echo -e "$txt" | while read line
do
# do smth with $line ...
a=$((a+1))
echo $a
done
echo "Final: $a"
Result:
So, this while-loop was executed in a new shell, and original variable $a was not changed.
Is it possible to use such piped loop within the same shell, or how to keep the changed value outside?
Thanks!