retrieve script name

  • Follow


Imagine a script script.awk with functions A, B, and C:

#!/usr/bin/awk -f
# script.awk -- just loading functions
function A(x)	{ return x }
function B(x)	{ return x*x }
function C(x)	{ return sqrt(x) }
# EOF

Now linking the script like
$ ln script.awk A
$ ln script.awk B
$ ln script.awk C

Would it be possible to retrieve the name of the script called within
AWK? I tried ARGV[0] but that gave me /usr/bin/awk.

So what I really want is the name of the script loaded with -f <script>.

The reason why I want this is to call the corresponding function within
the script, like in the action statement { print SCRIPTNAME($1) }. If it
were possible, the string SCRIPTNAME "(" $1 ")" would be needed to be
evaluated...

Any ideas?


0
Reply Rufus 2/18/2006 8:16:03 AM

"Rufus T. Firefly" <mb.atelier@web.de> writes:

> Would it be possible to retrieve the name of the script called within
> AWK? I tried ARGV[0] but that gave me /usr/bin/awk.

AFAIK, awk doesn't make available the name of the file passed with
-f. Your best bet is probably to call awk with a shell script, and
pass the name of the shell script to the awk program, e.g.

#!/bin/sh

awk -f script.awk "scriptname=${0##*/}"

Cheers,

        - Joel
0
Reply Joel 2/18/2006 10:13:50 AM


1 Replies
360 Views

(page loaded in 0.044 seconds)

Similiar Articles:













7/23/2012 12:12:31 AM


Reply: