osx - Full path to an awk script from within the script itself -
i have awk script, i.e., ascii file executable in linux in first line is:
#!/usr/bin/awk -f
i execute myscript this, if i'm in same directory:
> ./myscript afile
or this, if i'm in different directory:
> pwd /some_weird_path > /full_path/myscript afile
how can have access "/full_path/" within awk script itself? i've tried following without success:
argv[0] => /usr/bin/awk argv[1] => afile environ["pwd"] => some_weird_path
ideas?
this ugly seems work gnu awk on linux.
begin { getline cmdline <("/proc/"procinfo["pid"]"/cmdline") nf=split(cmdline,fields,/\0/) print fields[3] }
this uglier, should work on system ps
implementation, long neither path awk nor path script include whitespace characters:
begin { "ps -p "procinfo["pid"]" -ocommand=" | getline cmdline nf=split(cmdline,fields," ") print fields[3] }
ymmv.
Comments
Post a Comment