First, the shebang line is handled differently depending on the OS. I'm talking about GNU/Linux here, the leading operating system. ;)
The shebang line will be split only in two parts, the interpreter (usr/bin/perl) and the second argument which is supposed to prepend be the filename argument which itself will be append automatically when executing the shebanged file. Some interpreters need that. Like #!/usr/bin/awk -f
for example. -f
is needed in front of the filename argument.
Perl doesn't need the -f
to pass the perl file name, meaning it works like
perl file.pl
instead of
perl -f file.pl
That gives you basically room for one argument switch that you can choose, like
#!/usr/bin/perl -w
to enable warnings. Furthermore, since perl is using getopt() to parse the command line arguments, and getopt() does not require argument switches to be separated by spaces, you pass even multiple switches as long as you don't separate them, like this:
#!/usr/bin/perl -Xw
Well, as soon as an option takes a value, like -a foo
that doesn't work any more and such options can't be passed at all. No chance.
A more flexible way is to use a shell wrappper like this:
#!/bin/bash
exec perl -a -b=123 ... filename.pl
PS: Looking at your question again, you have been asking how to use perl switches together with /usr/bin/env perl
. No chance. If you pass an option to Perl, like /usr/bin/env perl -w
, Linux would try to open the interpreter 'perl -w'
. No further splitting.