count=0
function B() {
((count++))
}
function A() {
# sometimes calls B. count is incremented and stays that way.
B $1
...
# sometimes calls A which calls B. count is incremented.
# when returning to the parent A, count becomes what it was...
A $1
...
echo $count
}
unpack "$1"
echo $count
Example output:
1
2
3
(nested A calls B)
4
(back to parent A)
3
4
I tried using declare
or export
. Nothing.
It is as if there is a separate global scope for the nested function.
Using Ubuntu 22.04 on WSL2 VM.