You can try it if you want, save this into an executable file (test.awk):
#!/usr/bin/env awk -f
{ print $2 }
Then run: echo "Hello world again" | ./test.awk
I get the following: /usr/bin/env: awk -f: No such file or directoryDamn. I get "world" (OSX, zsh, BSD env)
So I supposed you can't pass options to `env` either (e.g. `-i`, or ENVVAR overrides?)
http://git.kernel.org/?p=linux/kernel/git/stable/linux-stabl...
$ cat x.py
#!/usr/bin/env python -i
$ ./x.py
/usr/bin/env: python -i: No such file or directoryAt a previous job, I spent hours rebuilding a ruby gem where someone had carelessly hard-coded "#!/usr/local/bin/ruby" into all of their executables.
Even if it looks like it works, don't do it! Stick to "#!/usr/bin/env ruby" for maximum compatibility, please.
Erm... you can do the exact same thing in Python, you know...
Once you start getting into Python/Ruby/Perl/etc scripts, the executable actually does matter and relying on env can make your script fragile with respect to path changes. Different executables have access to to different collections of installed libraries, and it's important to make sure that your scripts are run using the executable that has their dependencies installed. If you use env shebangs, there's no way to do that - you're limited to either using the first executable on the path or manually specifying the executable on the command line to bypass the shebang.
I'm not saying that you shouldn't use env shebags, because they really are fine for a lot of scripts. However, you should always be mindful of what they mean and how that could break your script in the future.
> it's important to make sure that your scripts are run using the executable that has their dependencies installed.
Which a hardcoded shebang path does not do, it assumes these things but does not assert them and does not "make sure" of anything.
> If you use env shebangs, there's no way to do that
There's no way to make unwarranted assumptions is about as far as it goes: using env shebangs, the caller of the utility has control over what happens and which executable gets called (even indirectly)
> you're limited to either using the first executable on the path or manually specifying the executable on the command line to bypass the shebang.
Or specify a PATH when calling the script, or run the script in overridden PATH environments (e.g. virtualenvs), or...
> I'm not saying that you shouldn't use env shebags, because they really are fine for a lot of scripts.
And I went (and would still go) much further and state that they're the right solution for the vast majority of scripts and utilities.
> However, you should always be mindful of what they mean and how that could break your script in the future.
So should you be with hardcoded shebang paths, and they are much more likely to break a script across porting than env shebangs.
If you need a specific version because of libraries or whatever, just use: #!/usr/bin/env python2.7
> When writing scripts, specify the full path to the executable you’ve installed in the first line of the script.
No. Don't do that. Bad. Even for maintenance and admin scripts, that makes them severely less portable and harder to keep in sync across machines for various reasons. Your path is setup correctly, just use that: there are very few reasons for your shebang lines to be anything other than:
This will make the shebang work using the normal rules of path-resolution, and means path-override tools and methods (e.g. python virtual environments, or `PATH=$somedirectory ./script`) will work correctly.edit: I am told not all versions of shebang/`env` support passing options to the $executable, and most notably it doesn't work on Linux. So don't do that, and i won't in the future. Still, $executable is usually sufficient