Thomas 'PointedEars' Lahn <
Point...@web.de> writes:
> Hongyi Zhao wrote:
>> On Tue, 23 Jul 2019 18:00:37 -0700, Keith Thompson wrote:
>>>> /usr/bin/env: ‘awk -f’: No such file or directory
>>>
>>> OK, so your system (what OS are you using?) doesn't support more than
>>> one argument to the command on a #! line.
>>
>> $ uname -a
>> Linux localhost 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u3 (2019-06-16)
>> x86_64 GNU/Linux
>>
>> Thanks for your instruction.
>
> I can confirm that the Shebang
>
> #!/usr/bin/env awk -f
>
> produces the error above on a Debian-based GNU+Linux distribution (if awk is
> alternatives-linked to gawk):
>
> $ uname -srvmo
> Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64 GNU/Linux
>
> (I am using Devuan GNU+Linux 2.0 “ASCII”.)
>
> The Shebang
>
> #!/usr/bin/awk -f
>
> works then.
Same on Ubuntu 18.04.2.
I was sure that some recent version of *some* OS had introduced the
ability to have multiple arguments on a #! line. I can currently find
no evidence in support of that. (I don't often use the "#!/usr/bin/env"
trick myself, so it likely wouldn't affect me one way or the other.)
A non-portable workaround: GNU Coreutils "env" starting with release
8.30 has a "-S" option For example, this:
#!/usr/bin/env -S awk -f
tells env to split the single argument "awk -f" into three separate
arguments, as if you typed "awk -f <name-of-script>" at a shell prompt.
(This should work even on systems where #! supports multiple arguments.)
Coreutils 8.30 is fairly new, and is likely not to be installed on
a lot of systems (Ubuntu 18.04.2 LTS has coreutils 8.28).
(My own preference is to use "#!/usr/bin/awk -f", and modify the "#!"
line as needed when installing scripts on a system where awk is
elsewhere.)