I get the error
/usr/bin/env: zsh -: No such file or directory
...when I run an executable zsh
script that starts with the following shebang line:
#!/usr/bin/env zsh -
Also, FWIW, replacing -
with --
causes /usr/bin/env
to print a similar complaint about zsh --
.
I have only seen this error under ubuntu, and only in the context of the shebang hack. Under darwin the same script runs fine. And under ubuntu, running
% /usr/bin/env zsh -
from the command line succeeds. (Actually, "under ubuntu" should be understood as short-hand for "under ubuntu 12.04 LTS and env (GNU coreutils) 8.13
".)
My question is: how can I modify the shebang above to avoid this error?
Of course, I know that removing the trailing -
will eliminate the error, but this is not an acceptable solution. The rest of this post explains why.
The shebang line that is causing the error comes about as an attempt to comply with two entirely independent guidelines:
To make scripts portable, use
#!/usr/bin/env <cmd ...>
rather than#!/path/to/cmd <...>
.Putting
-
as the sole argument tozsh
in the shebang line of zsh scripts thwarts certain types of attacks.
So, I can restate my question more precisely as follows: Is it possible to satisfy both of these guidelines without triggering the error shown above under ubuntu?
zsh
in the$PATH
anyway. – Gilles 'SO- stop being evil' May 02 '13 at 23:00#!/bin/sh
, but the same attacks, it seems to me, would be possible with#!/bin/zsh
. – kjo May 02 '13 at 23:13env
here anyway because you need to grab the interpreter from a well-known location (it's ok, but not very useful, to get it from$PATH
if that is set bysudo
). – Gilles 'SO- stop being evil' May 02 '13 at 23:21