Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I exit from BEGIN?

6 views
Skip to first unread message

bolta...@yahoo.co.uk

unread,
Oct 30, 2009, 8:20:54 AM10/30/09
to
Hi

I have a BEGIN section that does some checks first then needs to exit the
script if they fail. However exit() just causes the BEGIN section to exit
and it continues in the main section. I could obviously just set a variable
thats check in the main and END sections but this is a bit messy. Is there
a way of forcing the script to terminate in BEGIN?

Thanks

B2003


Kenny McCormack

unread,
Oct 30, 2009, 8:45:37 AM10/30/09
to

This is not current behavior.

I think this is our old friend, cause of many posts to this ng, "old AWK
on Solaris".

Use a current version of AWK.

P.S. It is true that exit causes the END block to be executed. This is
a different problem. TAWK (naturally) has a nice solution to this, but
in other AWKs, it has to be kludged one way or another.

Janis Papanagnou

unread,
Oct 30, 2009, 8:45:54 AM10/30/09
to
bolta...@yahoo.co.uk wrote:
> Hi
>
> I have a BEGIN section that does some checks first then needs to exit the
> script if they fail. However exit() just causes the BEGIN section to exit
> and it continues in the main section.

I couldn't reproduce what you say with current gawk. The main section will
not be executed, but the END section will.

What awk version are you using? Please post your script and small input and
output samples.

> I could obviously just set a variable
> thats check in the main and END sections but this is a bit messy. Is there
> a way of forcing the script to terminate in BEGIN?

A check in the END section might suffice.

Janis

>
> Thanks
>
> B2003
>
>

Janis Papanagnou

unread,
Oct 30, 2009, 8:47:26 AM10/30/09
to

How does tawk handle that?

Janis

pk

unread,
Oct 30, 2009, 9:00:31 AM10/30/09
to
Kenny McCormack wrote:

> P.S. It is true that exit causes the END block to be executed. This is
> a different problem. TAWK (naturally) has a nice solution to this, but
> in other AWKs, it has to be kludged one way or another.

Just out of curiosity, since you mention TAWK many times as being very good.
Is it available somewhere? This page

http://www.tasoft.com/tawk.html

does not have any download or purchase link, but at the same time, according
to their home page, development seems to have stopped. So is it the case
that if you didn't get it when it was available, you won't be able to get it
anymore?

bolta...@yahoo.co.uk

unread,
Oct 30, 2009, 9:03:37 AM10/30/09
to
On Fri, 30 Oct 2009 13:45:54 +0100
Janis Papanagnou <janis_pa...@hotmail.com> wrote:
>bolta...@yahoo.co.uk wrote:
>> Hi
>>
>> I have a BEGIN section that does some checks first then needs to exit the
>> script if they fail. However exit() just causes the BEGIN section to exit
>> and it continues in the main section.
>
>I couldn't reproduce what you say with current gawk. The main section will
>not be executed, but the END section will.

Ooops, my mistake. Its not executing the main section , just END as you say.
Because my END section is rather complicated I assumed it was executing
everything.

Ok , this doesn't matter so much now, it was the wasted CPU time in the
main section checking the flag variable that was concerning me as speed
is of the essense (yes I could have written it in C if I'd had time).

Thanks for everyones help

B2003


Ed Morton

unread,
Oct 30, 2009, 12:26:41 PM10/30/09
to

Learning about tawk when trying to figure out how to solve a problem
with awk is a bit like someone extolling the virtues of velociraptors
when you're trying to pick a guard dog. It's all very interesting and
seems to be relevant, but kinda irritates and frustrates you when you
decide to get one.

I think the reason Kenny keeps bringing it up, though, is that he
metaphorically wants someone to genetically engineer a rottweiler to
have a 3 inch razor sharp dewclaw... :-).

Ed.

Kenny McCormack

unread,
Oct 30, 2009, 1:43:02 PM10/30/09
to
In article <hcen8u$bi2$2...@svr7.m-online.net>,
Janis Papanagnou <janis_pa...@hotmail.com> wrote:
...

>> I think this is our old friend, cause of many posts to this ng, "old AWK
>> on Solaris".

Note: I just now checked on a Solaris box; it doesn't do this. So, I
take that comment back. I know there are some other "corner cases" that
behave weirdly in old AWK, in this general area. But this one isn't it...

>> Use a current version of AWK.
>>
>> P.S. It is true that exit causes the END block to be executed. This is
>> a different problem. TAWK (naturally) has a nice solution to this, but
>> in other AWKs, it has to be kludged one way or another.
>>
>
>How does tawk handle that?
>
>Janis

Re: TAWK:
1) TAWK has an abort() built-in that does what exit() really should
have done - that is, exit immediately. I realize, incidentally,
that there is a logical reason that exit() works as it does in
AWK, but I find it to be a nuisance more often than not.
2) TAWK also has nifty INIT, TERM, and EXIT blocks that give finer
control over the execution path in these sorts of edge cases.
3) To pk, re: availability. Alas, no. The company has become
non-responsive (as you've seen). The product (Windows version)
was last updated 11/21/1996. Still it is a helluva product, way
ahead of its time, given that GAWK is just now beginning to
"catch up". Shame, really. I personally was "that close" to
making a deal with them to (in some sense) take over
development, but it fell apart at the last minute. I keep
hoping they will re-surface in some form - either to continue to
sell it (in some fashion) or put it into the PD (maybe with a
GPL-ish license).

Ed Morton

unread,
Oct 30, 2009, 3:26:42 PM10/30/09
to
On Oct 30, 12:43 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <hcen8u$bi...@svr7.m-online.net>,
> Janis Papanagnou  <janis_papanag...@hotmail.com> wrote:
<snip>

> >> P.S.  It is true that exit causes the END block to be executed.  This is
> >> a different problem.  TAWK (naturally) has a nice solution to this, but
> >> in other AWKs, it has to be kludged one way or another.
>
> >How does tawk handle that?
>
> >Janis
>
> Re: TAWK:
>     1) TAWK has an abort() built-in that does what exit() really should
>         have done - that is, exit immediately.  I realize, incidentally,
>         that there is a logical reason that exit() works as it does in
>         AWK, but I find it to be a nuisance more often than not.
>     2) TAWK also has nifty INIT, TERM, and EXIT blocks that give finer
>         control over the execution path in these sorts of edge cases.
>     3) To pk, re: availability.  Alas, no.  The company has become
>         non-responsive (as you've seen).  The product (Windows version)
>         was last updated 11/21/1996.  Still it is a helluva product, way
>         ahead of its time, given that GAWK is just now beginning to
>         "catch up".  Shame, really.  I personally was "that close" to
>         making a deal with them to (in some sense) take over
>         development, but it fell apart at the last minute.  I keep
>         hoping they will re-surface in some form - either to continue to
>         sell it (in some fashion) or put it into the PD (maybe with a
>         GPL-ish license).

I expect you've probably tried this already but: have you come up with
a list of things tawk does that you'd like gawk to be able to do and
sent it to Arnold to see which, if any, he'd be interested in
developing for gawk or helping you develop it as some kind of add-on?

I can't think of any other way that the tawk features you want will be
picked up by another awk, but I'm just a user.

It seems pointless to post tawk information when no-one can use it,
but maybe you could post your "wish list" somewhere and refer
interested parties to it when appropriate?

Ed.

Kenny McCormack

unread,
Nov 2, 2009, 11:30:19 AM11/2/09
to
In article <07f7dffb-61c4-497a...@a32g2000yqm.googlegroups.com>,
Ed Morton <morto...@gmail.com> wrote:
...

>I expect you've probably tried this already but: have you come up with
>a list of things tawk does that you'd like gawk to be able to do and
>sent it to Arnold to see which, if any, he'd be interested in
>developing for gawk or helping you develop it as some kind of add-on?

No, I haven't and have no plans to. I'm perfectly happy with TAWK, and
I realize that GAWK will never catch up, so why should I bother?
It is not true that there aren't any other TAWK users besides me; there
are a couple others who post occasionally to this NG. The point,
however, is that my dream is that enough people get interested, to apply
some pressure to Pat Thompson to somehow make it available again.

>I can't think of any other way that the tawk features you want will be
>picked up by another awk, but I'm just a user.

See above. Why should I care?

>It seems pointless to post tawk information when no-one can use it,
>but maybe you could post your "wish list" somewhere and refer
>interested parties to it when appropriate?

It is not pointless to me. I think of TAWK as sort of a "reference
implementation" - i.e., this is the ideal of what an AWK implementation
should strive for. Note that this is not to say that TAWK is bug-free.
I've noticed several and have kept a list, but none are in any sense
show-stoppers - they're all pretty obscure and of the "doctor, it hurts
when I do this" variety. Feature-wise, I think TAWK does everything
that it should, and does it well.

I note, incidentally, that GAWK development is crippled by its attempt
to stay more-or-less POSIX conformant. I think that GAWK should have
two distinct modes of operations (as it already does; they just aren't
using this capability to the extent I'd like to see) - that is, the
default, good, fun mode, and the old-stodgy, POSIX-compliant mode. This
would give them the freedom to do the right thing, as long as the user
hasn't requested strict POSIX compliance.

A case-in-point is the recent thing about using built-in variables as
function parameters (see the post about how GAWK "fixed" this issue).
GAWK did the wrong thing - which was to just make it illegal. They
should have done the right thing (in the non-POSIX mode, of course),
which is to make it work like it should. That is, if you code:

function foo(FS) { ... }

Then within function foo(), FS is the value passed as an arg, and the
old value is restored on exit from foo(). I have actually wanted this
functionality from time-to-time - to be able to pass a parameter to a
routine that is the FS value to use for that routine. Yes, I know there
are workarounds, but the cleanest approach would be to have it work like
this. Note, incidentally, that TAWK does not do this (they didn't get
it right, either). But, as I say, GAWK has the chance to do it right
(but for that darn POSIX-compatibility thing).

Ed Morton

unread,
Nov 2, 2009, 12:12:11 PM11/2/09
to

For what it's worth, I think throwing an error when someone tries to use
a built-in variable as a function argument was the right approach for
many reasons, but I can see both sides.

I think, though, that trying to make gawk POSIX-compliant in the things
POSIX specifies is the right general approach. i.e. if POSIX specifies
a, b, and c then in any mode gawk should do a, b, and c, but when not in
POSIX compliant mode gawk should additionally do d, e, f, etc. - i.e. we
should have gawk extensions to POSIX rather than gawk differences from
POSIX.

So, in this case since it sounds from your post like POSIX declares that
you can't use a builtin variable as a function argument, and there's a
trivial alternative way to set FS locally within a function, I think
even IF allowing builtin variables as arguments was clearly a better
approach, the gawk folks would've been wrong to implement something
different and then have to support both approaches in different modes.

Out of curiosity - any idea why tawk got discontinued?

Ed.

Anton Treuenfels

unread,
Nov 2, 2009, 6:54:30 PM11/2/09
to

"Ed Morton" <morto...@gmail.com> wrote in message

> Out of curiosity - any idea why tawk got discontinued?

PURE SPECULATION: Perl killed it (free vs. $$)

I've never regretted the money, though. Besides, TAWK is compiled, not
interpreted, so it's much faster than any Perl.

- Anton Treuenfels

Kenny McCormack

unread,
Nov 3, 2009, 7:52:34 AM11/3/09
to
In article <r_-dndxEDbGn7HLX...@earthlink.com>,

Anton Treuenfels <teamt...@yahoo.com> wrote:
>
>"Ed Morton" <morto...@gmail.com> wrote in message
>
>> Out of curiosity - any idea why tawk got discontinued?
>
>PURE SPECULATION: Perl killed it (free vs. $$)

That's like saying that Hip Hop (aka, cRap) killed R&R. It may be true,
but it's no reflection on R&R. It is a reflection on the user-base.

>I've never regretted the money,

It will come as no surprise to hear that ITA.

>though. Besides, TAWK is compiled, not
>interpreted, so it's much faster than any Perl.

Well, those are fighting words, of course.

But just to be fair, I will point out that TAWK is interpreted. It is
"compiled" only in the sense of "encrypted" (we've had this discussion
before - about how many script languages are "compiled", but the sense
of being "compiled" is really only for the purpose of encryption).

According to Pat hi,self: TAWK is interpreted; it just has a much faster
interpreter than anyone else's.

0 new messages