I don't think this is possible as per gawk
documentation:
Finally, the value of
ARGV[0]
(see section 7.5 Built-in Variables) varies depending upon your operating system. Some systems putawk
there, some put the full pathname of awk (such as/bin/awk
), and some put the name of your script ('advice'). Don't rely on the value ofARGV[0]
to provide your script name.
On linux
you can try using a kind of a dirty hack and as pointed in comments by Stéphane Chazelas it is possible if implementation of awk
supports NUL bytes:
#!/usr/bin/awk -f
BEGIN { getline t < "/proc/self/cmdline"; split(t, a, "\0"); print a[3]; }