[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with command block I/O redirection...
From: |
Paul Jarc |
Subject: |
Re: problem with command block I/O redirection... |
Date: |
Mon, 27 Aug 2001 17:16:53 -0400 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7 |
"Perry Dykes" <pdykes@us.ibm.com> wrote:
> When I use a command block w/ I/O redirection include a pipe, I get
> different results and variables do not scope correctly.
Each element of a pipeline is run in a separate process. So variable
settings, etc., will not be visible except within that same pipeline
element. This is related to FAQ entry E4.
> retvalue=1
> {
...
> retvalue=$?
> } 2>&1 | tee outfile.txt 2>&1 (Line a)
Move the code that uses retvalue inside the { } pipeline element:
exec 3>&1
{
...
echo "$retvalue" >&3
} | tee outfile.txt
Or try this (won't work for some other sh interpreters):
exec 3>&1 4>&2 > >(tee outfile.txt) 2>&1 # save stdout & stderr, then redirect
retvalue=1
...
exec 1>&3 2>&3 # restore stdout & stderr
paul