I wrote the following script:
bar() {
echo $(foo) >&2
echo "bar" >&2
echo $VARIABLE >&2
}
foo() {
echo "foo" >&2
VARIABLE="test"
echo $VARIABLE >&2
}
bar
The output is
foo
test
bar
But if I wrote this:
bar() {
foo
echo "bar" >&2
echo $VARIABLE >&2
}
foo() {
echo "foo" >&2
VARIABLE="test"
echo $VARIABLE >&2
}
bar
It prints what I need:
foo
test
bar
test
The question is that I need to send foo
's result to &2
yet I need the VARIABLE
value that was set when calling to foo
. How to do this in bash?