[tex-live] how robustly call awk script?

Hartmut Henkel hartmut_henkel at gmx.de
Sun Jan 14 19:15:44 CET 2007

Hi Sanjoy,

On Sun, 14 Jan 2007, Sanjoy Mahajan wrote:

> > It means that env took the "-f" option which you want to pass to awk.
> Right.  I straced x.sh which is a simple script to total the numbers
> on stdin (I use it to unbalance my checkbook):
> #!/usr/bin/env awk -f
> BEGIN {total=0};
> {total += $1}
> END {print total}
> and it had these lines as it tried to find awk on the path:
> ...
> execve("/usr/bin/awk -f", ["awk -f", "./x.sh"], [/* 36 vars */]) = -1
> ENOENT (No such file or directory)
> So env stupidly combines the -f with the program name, making argv[0]
> = "awk -f", and searches for a binary named "/usr/bin/awk -f" (!)
> which will never be found.
> Without the -f, i.e. "#! /usr/bin/env awk", it won't work at all
> because awk thinks the rest of the file are lines to be processed,
> rather than pattern text.  So I think your solution

no, Nelson's :-)

> is the only portable one.

ah, thanks a lot for investigation, so let's be happy that at least perl
does not need a -f :-)

Regards, Hartmut

BTW, i tried a few more, but i didn't get a single application of awk
running together with env, neither in -f nor in '...' mode, if it's in
an executable file. No problem on the command line however. If anybody
has an example... :-)

More information about the tex-live mailing list