Re: Possible bug with tee or variable scope ??
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Wed, 28 Jun 2006 20:37:56 +0100
2006-06-27, 17:16(-07), Chris:
It seems that tee can influence the scope of a variable. This script[...]
below shows a variable not changing when tee is used and changing (as
expected) when tee is not used:
#!/bin/ksh
Name="Init"
change_name ()
{
echo " Fn before: $Name."
Name="Changed"
echo " Fn after : $Name."
}
echo "Before tee : $Name."
change_name | tee /dev/null
echo "After tee : $Name!"
change_name
echo "After no tee: $Name."
What you could do is:
{
{
echo "Before tee : $Name." # goes to stdout
change_name >&3 # goes to tee
echo "After tee : $Name!"
change_name
echo "After no tee: $Name."
} 3>&1 >&4 4>&- | tee some files
} 4>&1
Note that zsh has built in support for the tee functionality:
echo foo >&1 > some-file
outputs foo\n both to stdout and to some-file (setopt nomultios
to disable it). And "echo foo" is not started in a subshell (zsh
spawns a background process that reads the output of "echo foo"
via a pipe and tees it to both stdout and some-file, just as |tee
does)
--
Stéphane
.
- References:
- Possible bug with tee or variable scope ??
- From: Chris
- Possible bug with tee or variable scope ??
- Prev by Date: Re: no globbing by redirection?
- Next by Date: Re: grep with regex in tcsh
- Previous by thread: Re: Possible bug with tee or variable scope ??
- Next by thread: Associate BACKSPACE key to 'erase' permanently
- Index(es):
Relevant Pages
|