GNU bug report logs - #22205
tee bug?

Previous Next

Package: coreutils;

Reported by: Nacho Esteban <juanignacio.esteban <at> alliance-healthcare.net>

Date: Fri, 18 Dec 2015 16:31:03 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


Message #7 received at control <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Nacho Esteban <juanignacio.esteban <at> alliance-healthcare.net>,
 22205-done <at> debbugs.gnu.org
Subject: Re: bug#22205: tee bug?
Date: Fri, 18 Dec 2015 09:43:51 -0700
[Message part 1 (text/plain, inline)]
tag 22205 notabug
thanks

On 12/18/2015 06:18 AM, Nacho Esteban wrote:
> Hi team,
> 
> I detected an strange behaviour of tee command that may bee a bug.

Not a bug in tee, but intentional behavior of your shell.

> 
> Please consider this script snippet
> 
>    VAR=""
> 
>    A() {
>         VAR="This is my value"
>         echo "VAR in $FUNCNAME: $VAR"
>    }
> 
>    BA() {
>         A | tee /tmp/kk

You are using a pipeline.  Shells implement pipelines by running the
left command (here, the function A) in a subshell. (POSIX also says that
the right command can also be a subshell, but there it is not required;
ksh runs the right command in the current shell, and bash used to run it
in a subshell but new enough bash now has a knob you can turn on to
emulate ksh behavior).

Therefore, all changes to the environment made during the execution of A
are local to that subshell, and are lost as soon as the subshell exits.

>         echo "VAR in $FUNCNAME: $VAR"

Thus, here you print the value of $VAR as it was before A ran, since
running A does not affect the current shell.


> In fact if "| tee /tmp/kk" is removed value of VAR is properly visible
> from BA function:

Because then you no longer have a subshell, so now the execution of
function A affects the current shell.  Again, not tee's fault.  You
could replace it with "| :" and see the same effect.

> This e-mail (including any attachments) is confidential and may be
> privileged or

Such a disclaimer is unenforceable on publically-archived lists, and you
may want to consider not using your employer's spammy email gateway when
sending mail to public lists.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 9 years and 159 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.