Because interpreters such as zsh, bash, python, perl may be located in different places on the filesystem, scripts often have a shebang that uses env
for portability, e.g. #!/usr/bin/env zsh
. However, as http://en.wikipedia.org/wiki/Shebang_(Unix)#Portability explains, many systems including Linux don't allow the passing of arguments to the interpreter.
Often, I'd like to do something like #!/usr/bin/env zsh -f
to prevent my script to ever read my ~/.zshenv
, or I'd like to do #!/usr/bin/env perl -w
, etc. This works on OS X, but not on Linux.
What is the workaround for that? Can I have the best of both worlds: portability and arguments for the interpreter? If possible, give a general workaround that works for all interpreters, not just zsh.
Best Answer
Here's an inline solution to work around the portability problem for ZSH.
Some other methods to try include
--options
such as doing--options
being passed in do not affect the load behaviorinvoke.sh
script instead of /usr/bin/env to use your PATH, calling with/path/to/invoke.sh script
with your script starting with#! zsh -f