|
The inner loop is a sub-process. Anything changed there has no effect on the parent process. It's the same situation as
X=1
bash -c "X=2"
echo $X
Both of your loops are reading from stdin. Each process only has 1 stdin so your two loops absolutely need to be separate processes.
|