I have two scripts that call each other. I need to modify a given variable in both. It doesn't work.
A.sh :
#! /bin/sh
funcA() {
echo "var B in funcA (1) $__varB"
__varB="xxx"
echo "var B in funcA (2) $__varB"
}
. B.sh
B.sh :
! /bin/sh
__varB="asdf"
funcA | tee -a out.txt 2>&1 #if no pipe then it works
echo "var B in B.sh $__varB"
Execution
./A.sh
var B in funcA (1) asdf
var B in funcA (2) xxx
var B in B.sh asdf
If in B I do not pipe funcA into tee then it works as expected and __varB is modified. My problem is that in the real case I can't modify B.sh.
What can I do in A.sh so that I modify __varB ?