Hi,
Is this expected behavior when calling a sub using tee?
Test script is as below:
$: cat tee.bash
#!/bin/bash
#
export x=YES
export LOG=/tmp/setvar.OUT
setvar ()
{
echo "Hello World"
x=NO
}
cat /dev/null > $LOG
echo "## STARTING with x=YES | x=${x}"
echo "calling setvar TO set x to NO"
setvar
echo "## RAN setvar | x should be NO | x=${x}"
x=YES
echo "## RESETTING x to YES | x=${x}"
echo "calling setvar with tee"
setvar | tee -a $LOG
echo "## RAN setvar WITH tee -a | x should be NO BUT IT ISN'T. IS THIS EXPECTED BEHAVIOR? | x=${x}"
RUNTIME of the tee.bash script
$: ./tee.bash
## STARTING with x=YES | x=YES
calling setvar TO set x to NO
Hello World
## RAN setvar | x should be NO | x=NO
## RESETTING x to YES | x=YES
calling setvar with tee
Hello World
## RAN setvar WITH tee -a | x should be NO BUT IT ISN'T. IS THIS EXPECTED BEHAVIOR? | x=YES
$:
$: cat /tmp/setvar.OUT
Hello World
$:
This is just an excerpt of the script. The whole sub has several echo commands that I am wanting to append to a log file.
At the moment, because of this behavior, I am just doing the tee -a inside the sub instead of when the sub is called. That is, I have it as below in the sub.
echo "Hello World" | tee -a ${LOG}
Please advise. Thanks.