* 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-02 9:41 very weird echo problem Uli Zappe
@ 1997-03-03 9:37 ` Peter Stephenson
1997-03-03 11:55 ` Uli Zappe
0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 1997-03-03 9:37 UTC (permalink / raw)
To: Uli Zappe, Zsh users list
Uli Zappe wrote:
> log_function()
> {
> DATE=$(date)
> echo $MESSAGE
> echo $MESSAGE >> $LOGFILE
> }
>
> log_function TEST1; log_function TEST2
> log_function TEST3; log_function TEST4
>
> 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
Hmm, you can't be telling us everything since TEST1 and TEST2 are
passed as positional parameters, which don't get used by log_function.
How does $MESSAGE get set? Can you produce an actual minimal script
which shows this?
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very weird echo problem
1997-03-03 9:37 ` Peter Stephenson
@ 1997-03-03 11:55 ` Uli Zappe
1997-03-03 14:46 ` gwing
0 siblings, 1 reply; 7+ messages in thread
From: Uli Zappe @ 1997-03-03 11:55 UTC (permalink / raw)
To: zsh-users
Peter Stephenson wrote:
> Hmm, you can't be telling us everything since TEST1 and TEST2
> are passed as positional parameters, which don't get used by
> log_function. How does $MESSAGE get set? Can you produce an
> actual minimal script which shows this?
Oops, sorry, I got a bit too schematic ;-)
It must read:
log_function()
{
DATE=$(date)
echo $1
echo $1 >> $LOGFILE
}
log_function TEST1; log_function TEST2
log_function TEST3; log_function TEST4
In the actual script, $DATE is included in the second echo (to the
logfile), but the effects I describe are reproducable also the way
that I have notated log_function here.
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 11:55 ` Uli Zappe
@ 1997-03-03 14:46 ` gwing
1997-03-03 16:54 ` Uli Zappe
0 siblings, 1 reply; 7+ messages in thread
From: gwing @ 1997-03-03 14:46 UTC (permalink / raw)
To: Uli Zappe; +Cc: zsh-users
[-- Attachment #1: Type: application/pgp, Size: 1486 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: very weird echo problem
1997-03-03 14:46 ` gwing
@ 1997-03-03 16:54 ` Uli Zappe
0 siblings, 0 replies; 7+ messages in thread
From: Uli Zappe @ 1997-03-03 16:54 UTC (permalink / raw)
To: zsh-users; +Cc: gwing
Geoff Wing wrote:
> Can you produce more of the script? There isn't enough there to
> determine what the problem is. I produced no problems from a
> cron job or via other non-tty specific methods either with 2.5.03
> or 3.* Thanks
You got me wrong. This actually IS practically the complete test
script (well, #!/usr/bin/zsh is missing, and you should replace
$LOGFILE by a name...) which reproduces the problem on my machine.
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.
It also works fine if I apply one of the following changes to log():
1.******************************
DATE=$(date)
echo $1 1>&1
echo $1 >>/log
2.******************************
date
echo $1
echo $1 >>/log
3.******************************
DATE=$(date)
echo $1 >>/log
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).
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, 0 replies; 7+ messages in thread
From: Uli Zappe @ 1997-03-03 23:21 UTC (permalink / raw)
To: zsh-users
Wolfgang Hukriede <whukriede@ifm.uni-kiel.de> wrote:
> Hello, I checked your script under Nextstep3.2 and zsh 3.0.2 with
> and without cron, it runs flawless.
Aha!! I've tried it myself with zsh 3.02, and it works! So this is
obviously a bug and I'm not as stupid as I was afraid I am... :-)
> Do yourself a favour and upgrade.
As far as I'm concerned, I'd love to do this, but the script will
be published for the whole NEXTSTEP community and I can't build on
something that's not a standard part of NEXTSTEP.
Anyway, thanks to this crazy workaround 1>&1 (can't believe I found
that one!) it will work...
Thanks a lot!
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).