Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
very weird echo problem
- X-seq: zsh-users 733
- From: Uli Zappe <uli@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx
- Subject: very weird echo problem
- Date: Sun, 2 Mar 97 10:41:55 +0100
Hi,
excuse me for bothering you again but I have experienced another
(to me) very strange problem.
I want to log messages of a shell script to both standard output
and a logfile, and have to do a "date" call before.
If I do something like
DATE=$(date)
echo $MESSAGE
echo $MESSAGE >> $LOGFILE
everything works as expected.
However, as soon as I capsulate this in a shell function:
log_function()
{
DATE=$(date)
echo $MESSAGE
echo $MESSAGE >> $LOGFILE
}
weird things happen.
Assume in my script I have the following function calls:
log_function TEST1; log_function TEST2
log_function TEST3; log_function TEST4
then:
A. If I execute the script from a TERMINAL everything is fine
(messages get printed to the terminal and to the log file)
B. If I execute the script NOT FROM A TERMINAL (but e.g. cron), then
the script will stop after the first LINE with log_function calls
(NOT the first log_function!), i.e. it will print
TEST1
TEST2
to the logfile and then STOP EXECUTION of any code following
C. As soon as I COMMENT OUT ANY ONE of the 3 lines of the log
function (i.e. no date, or one of the two echo's missing)
everything again will work as expected. (Concerning date, it is
sufficient to not put it into a variable, i.e. a pure "date" as
the first line does no harm.)
The workaround I have found is to write the first echo line as
echo $MESSAGE 1>&1
i.e I redirected stdout to itself...!?! This shouldn't change
anything, one would expect, but in fact it solves the problem. Now
everything works, but as hard as I've tried I simply don't
understand WHY. Am I totally confused or is this a bug? (I have to
still use zsh 2.5.02, if that matters).
Thanks for any insight!
Bye
Uli
______________________________________________________________________
Uli Zappe E-Mail: uli@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
(NeXTMail,Mime,ASCII) PGP on request
Lorscher Strasse 5 WWW: -
D-60489 Frankfurt Fon: +49 (69) 9784 0007
Germany Fax: +49 (69) 9784 0042
staff member of NEXTTOYOU - the German NEXTSTEP/OPENSTEP magazine
______________________________________________________________________
Messages sorted by:
Reverse Date,
Date,
Thread,
Author