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: Joep van Delft
Subject: Re: [bug-gawk] Can a GAWK script access its full path\name at "run-time?
Date: Thu, 14 May 2015 11:11:26 +0200

On Wed, 13 May 2015 19:28:04 +0300
Eli Zaretskii <address@hidden> wrote:

> > From: Aharon Robbins <address@hidden>
> > Date: Wed, 13 May 2015 09:03:53 +0300
> > 
> > Also note that -E and its argument do not show up in ARGV.
> > Because of this, -E does not solve the original poster's question
> > of how to get the full path name of the script being run.
> 
> How about adding a field to PROCINFO[] where we would save the full
> original command line?

Have been trying to understand what is going on from a user
perspective.  I found this oneliner instructive: 

    % gawk -n -e \
    'BEGIN{for(i=0; i in ARGV; i++)
    printf "ARGV[%i] = <%s>\n", i, ARGV[i] 
    }' -a -b -c abc     

    ARGV[0] = <gawk>
    ARGV[1] = <-a>
    ARGV[2] = <-b>
    ARGV[3] = <-c>
    ARGV[4] = <abc>

Everything up to and including the program text has been subsumed
into a generic "gawk" in ARGV[0].  This makes sense, as the gawk
runtime already has internalized these settings. 

What is still there, is left as file.  Here, the user has the
possibility to intervene in the processing of the command line. 

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). 

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? 

Kind regards, 

Joep




reply via email to

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