Quantcast
Channel: How to print own script name in mawk? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by taliezin for How to print own script name in mawk?

$
0
0

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 put awk 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 of ARGV[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]; }

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>