I've a simple script:
#!/usr/bin/env perl -w
print "Hello World\n"
Make this executable, run on Linux, and I get:
/usr/bin/env: perl -w: No such file or directory
(without the -w, this works OK)
Running the same script on a Solaris 8 machine produces the correct output.
Any suggestions as to why this is ?
It's not
env
; it's the kernel's#!
handler. Everything after the first word (/usr/bin/env
) is passed as a single argument string. Safest/most portable is to not put anything after theperl
there.Which shell are you using on both machines? Also, which version of Solaris and Linux are you using?
It's possible that you're using KSH on Solaris by default and BASH on Linux. This difference may affect how the shebang line is executed.
HTH!
Tom Purl
The wikipedia article mentions this portability issues:
http://en.wikipedia.org/wiki/Shebang_%28Unix%29
"Another portability problem is the interpretation of the command arguments. Some systems [12] do not split up the arguments; for example, when running the script with the first line like,..."
I found this a bit surprising, but it is the shell that does the parsing of arguments on spaces, and there isn't a shell involved here.