zsh-users
 help / color / mirror / code / Atom feed
* very weird echo problem
@ 1997-03-02  9:41 Uli Zappe
  1997-03-03  9:37 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Uli Zappe @ 1997-03-02  9:41 UTC (permalink / raw)
  To: zsh-users

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@tallowcross.uni-frankfurt.de
                                (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
______________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: very weird echo problem
@ 1997-03-03 18:01 Wolfgang Hukriede
  1997-03-03 23:21 ` Uli Zappe
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Hukriede @ 1997-03-03 18:01 UTC (permalink / raw)
  To: zsh-users


Hello, I checked your script under Nextstep3.2 and zsh 3.0.2 with
and without cron, it runs flawless.

Do yourself a favour and upgrade. Even when Nextstep 3.3 came out,
Next should have included zsh 2.5.03 (was the production release
then and less buggy due to my experience) instead of 2.5.02.

There's even a precompiled binary (3.0.2) in the usual channels, if
you don't want to install from the sources, which indeed is quite
easy. "Works like a charm", as they say.

I don't know about the new 3.1 series though.

Greetings, Wolfgang.

--------------------------------------------------------------------
Uli Zappe <uli@tallowcross.uni-frankfurt.de> wrote

> Here is the actual one with which I just tested it again:
>
>
> ***********************************************************
> #!/usr/bin/zsh
>
> log()
> {
> DATE=$(date)
> echo $1
> echo $1 >>/log
> }
>
> log TEST; log TEST_SAME_LINE
> log TEST_NEXT_LINE
> ************************************************************
>
> This script will only write
>
>         TEST
>         TEST_SAME_LINE
>
> to /log when called by cron. It works fine when called from a shell.

...

> I'm using zsh 2.5.02 under NEXTSTEP 3.3 Intel. (2.5.02 is the
> distribution that is included in NEXTSTEP 3.3).


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-03-03 23:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-02  9:41 very weird echo problem Uli Zappe
1997-03-03  9:37 ` Peter Stephenson
1997-03-03 11:55   ` Uli Zappe
1997-03-03 14:46     ` gwing
1997-03-03 16:54       ` Uli Zappe
1997-03-03 18:01 Wolfgang Hukriede
1997-03-03 23:21 ` Uli Zappe

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).