Skip to main content
2 of 10
Ensure interpreter is GNU awk
Thor
  • 17.5k
  • 3
  • 55
  • 71

I don't know any direct way of getting the command name from within awk. With GNU awk running on GNU/Linux you can use the process ID and ps to retrieve the command name as a workaround. For example:

cmdname.awk

#!/usr/bin/gawk -f

BEGIN {
  "ps -p " PROCINFO["pid"] " -o comm=" | getline CMDNAME
  print CMDNAME
}

Output:

cmdname.awk
Thor
  • 17.5k
  • 3
  • 55
  • 71