I'm trying to watch and output the progress of a longer script. (Later I want to use the Progress to calculate a progress bar).
Here is a shortened example:
#!/bin/bash
PROGRESS=0
updateprogress () {
PROGRESS=$((PROGRESS + 1))
echo $PROGRESS
}
<do something>
updateprogress
sudo cat /root/.virtualMachines | while read -r name ipAddr # <-7 lines
do
<do something>
updateprogress
done
sudo cat /root/.virtualServices | while read -r name ipAddr # <-3 lines
do
<do something>
updateprogress
done
What I would expect now would be an Output like
1 <-# before the first while)
2
3
4
5
6
7
8 <-# end of first while)
9
10
11 <-# end of second while)
But what I get is
1 <-# before first while)
2
3
4
5
6
7
8 <-# end of first while
2
3
4 <-# end of second while
So the issue has to be something about the global/local scope but how can I use only the global variable $PROGRESS I defined at the top for all function calls?