Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

very weird echo problem


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

   echo $MESSAGE
   echo $MESSAGE >> $LOGFILE

everything works as expected.

However, as soon as I capsulate this in a shell function:

      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


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
   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!



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