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: Tue, 12 May 2015 23:36:28 +0200

On Tue, 12 May 2015 14:47:33 +0300
Aharon Robbins <address@hidden> wrote:

> Hello. Re this:
> 
> > Date: Tue, 12 May 2015 10:11:48 +0900
> > From: green fox
> >
> > The only reliable way at the moment is to load all scripts, then
> > at the last script, call the cmdline parser. But then the argv is
> > trimmed.
> 
> While access to the raw argv would be nice, that's not how awk has
> ever worked, nor is that how POSIX defines it.  Sorry.

I respectfully disagree. 

For the use case of loading library files from an awk program
dynamically, this holds true, but for another reason. You cannot use a
variable to @include files (I guess because the @include directives
are processed before the BEGIN{}-block gets executed). Gawk, however,
*does* provide raw access to the ARGV array with the -E (or --exec)
option. 

--exec instructs gawk to not do any processing of the command line.
You'll get responsibility of processing anything of interest, and
deleting the processed items from the ARGV array. 

After the BEGIN{}-block has finished and gawk needs to use files, it
will treat everything that is left in ARGV as a file. 

The info and man pages say it is useful for security in CGI-scripts,
but that application feels a bit antiquated. 

> Note that even with such access, there's no easy way to
> reconstitute the absolute path of any given script, since pathnames
> could be relative, and also since scripts can be found via a path
> search.

True that. 

Kind regards, 

Joep






reply via email to

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