7
1
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.
For the zsh-specific workaround, I prefer the following myself
[ "x$ZSH_VERSION" = "x" ] && exec zsh -f "$0" "$@"
– huyz – 2011-05-10T06:55:53.290Thanks for the research. I didn't know that
#! /usr/bin/env POSIXLY_CORRECT=1 bash
would work. – huyz – 2011-05-10T06:57:52.8031I guess there is no single "general solution" that no one else can offer. So I'll accept your answer. Hopefully someday Linux gets with the program. – huyz – 2011-07-05T06:33:34.880
#! /usr/bin/env POSIXLY_CORRECT=1 bash
doesn't work as it is as though you wrote/usr/bin/env "POSIXLY_CORRECT=1 bash" script
at the shell. – r3m0t – 2013-04-04T20:03:11.607