tag 22205 notabug
close 22205
stop
On 18/12/15 13:18, Nacho Esteban wrote:
> Hi team,
>
> I detected an strange behaviour of tee command that may bee a bug.
>
> Please consider this script snippet
>
> VAR=""
>
> A() {
> VAR="This is my value"
> echo "VAR in $FUNCNAME: $VAR"
> }
>
> BA() {
> A | tee /tmp/kk
> echo "VAR in $FUNCNAME: $VAR"
> }
>
> This is the output when when executed:
>
> $ BA
> VAR in A: This is my value
> VAR in BA:
>
>
> I miss the value of VAR inside BA function.
>
>
>
> In fact if "| tee /tmp/kk" is removed value of VAR is properly visible from
> BA function:
The reason is due to the "|", not tee.
You can see that by replacing the tee with cat.
The pipe is implemented in a subshell and thus
can't propagate the VAR back to the current shell.
cheers,
Pádraig