[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with command block I/O redirection...

From: Perry Dykes
Subject: problem with command block I/O redirection...
Date: Mon, 27 Aug 2001 15:20:42 -0500

When I use a command block w/ I/O redirection include a pipe, I get
different results and variables do not scope correctly. Goal is to store
all executed lines and results into a logfile and to console during the run
of command block. Also, want to pass the return value (retvalue in this
script) to main scope and use as an exit value.  The exit value is
different if ... | tee ... is included.

Example script:

set -x
set -x
# junk example of executing basic commands
ls -al
read text junk
echo "$text"
echo "$junk"
echo "this is some test"
grep -e "junk" junk
# key command, wish to keep return value, and provide to main scope and
exit script with this return code (make diff than 1 on purpose for test)
grep -CXT bla
} 2>&1 | tee outfile.txt 2>&1   (Line a)
#}                                                  (Line b)
echo $?
echo $retvalue
exit $retvalue

If Line b is uncommented (and Line a commented out), the retvalue variable
value set in command block is reflected in main scope and at the exit the
script returns the correct value, however, my logfile is not obviously
created. If the Line a is used, the output of function is not the value of
retvalue, the value of this variable is not reflected in global scope.

When a command block ({ }) is used, any value set (retvalue specifically)
(since local keyword cannot be even used in this context) should be
reflected in high level scope. However, in this case, the inclusion of ...
| tee ... causes a problem.

Is this a design feature, or bug?

Version stuff (running from cygwin currently):

$ bash -version
+ bash -version
GNU bash, version 2.05.0(6)-release (i686-pc-cygwin)
Copyright 2000 Free Software Foundation, Inc.

Perry Dykes

tel: (507)253-6385 t/l 553-6385
fax:507-253-5737 t/l 553-5737

reply via email to

[Prev in Thread] Current Thread [Next in Thread]