bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Can a GAWK script access its full path\name at "run-time?


From: Aharon Robbins
Subject: Re: [bug-gawk] Can a GAWK script access its full path\name at "run-time?
Date: Fri, 15 May 2015 06:12:34 +0300
User-agent: Heirloom mailx 12.5 6/20/10

> I could see some use to having at least the program name under which
> it has been called available somewhere.  The behavior of the program
> could then be changed when called under a different name
> (symlinking). 

GNU standards disallow basing behavior on the program's name.  But
the real issue is #!. On different systems, if you have foo.awk with

        #! /usr/bin/gawk -f

then the C level argv[0] might be any of "foo.awk", "gawk", "/usr/bin/gawk",
or who knows what.  This is documented in the manual; you just can't
rely on the value of ARGV[0] to be anything useful. Sad, but true.

> On a related note: I did not find a way to make the debugger spit out
> information on how the gawk runtime has been set up.  Formulated
> differently, what is hiding behind the word "gawk" in ARGV[0].  Did I
> overlook something? 

There isn't any way, for the reasons just described.  The gawk_name
function Eli mentioned isn't all that helpful; it pulls out the final
component of argv[0] but does it correctly for *nix, VMS, and anything
else where it matters.

Thanks,

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]