In some, it's not supported at all, and asking a shell to run a non-binary always runs it in the shell. In others, there's a limit on the path length in the hashbang line, so! The simplest solution to avoid the error is to have only one argument to the sh call on some systems and also seems to be to add the option -x to the perl call [d]. And I say seems because it depends on the system, kernel, shell and perl used to call the script.
In the same page 21 is the script you posted. The next script about this issue, is in page keep reading. Note: The inclusion of the perl name word in the first line is only needed if the script is at any time going to be called as perl. In that case, that word will stop perl from looping.
In fact, the second example from the book page is:. In which the comment part of - - perl - - -p is explained in the book as being interpreted by perl and mostly ignored.
However, that is assuming that the shell call! That is not true in some systems. Understand that the script may be called as sh script , bash. Would be interpreted by almost any shell either called as. Also, the kernel will accept and process -- as an argument meaning "end of options" [a] [b].
That is the line:. The first word eval will convert the list of arguments into a command line to execute removing one layer of quoting. That is, it will be converted to this command line:.
The first word of this new command line that is: exec will tell the kernel to replace the running process with the executable perl searched in the PATH and the arguments that result from expanding the rest of the command line. It is then perl that loads the script and re-interprets its content.
Comments in Perl also start with a Thus, the first line shebang is a comment to Perl. This third line makes Perl not execute the second line. A very long way of writing a nop. A "hello world" example similar to and using the -x perl option as usually recommended in the perldoc site. Adding the -x call to perl will ensure that perl will itself search for a! This -x will also make the if 0 superfluous. That will set a quite more portable PATH to search for the perl executable.
More variables could be set to make the call to perl more reliable if needed. That makes the separation between shell and perl quite more clear. In such case, the whole string -- perl, to stop looping could be reported as an error. As it is if bash directly loads the script when executing. Read more detail in search for "Splitting arguments". Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
The drawback is that the perl listed in the hash-bang line is only used if the script is executed as. If it is executed as perl hello. Which might be a different version of perl from the one in the hash-bang line. When Bash sees this line it will first run the env command passing the name perl to it.
So if we have! Both when it is executed as. This too has a disadvantage, because this relies on the users setting their PATH environment correctly. Here is a table that tries to explain the 4 cases: the hash-bang Which perl is used to run the script when call it either of these ways:. You will probably see lots of scripts starting with! The -w in this hash-bang turns on warnings. This is quite similar to what use warnings does, but this is the old style.
You won't see this in most of the modern Perl scripts. Another common flag that you might see on the hash-bang lines are -t and -T. They turn on the so-called taint-mode that will help you write more secure code. Toggle navigation Perl Maven. Standard output, standard error and command line redirection Warning when something goes wrong What does die do? Unknown warnings category Can't use string Symbolic references in Perl Can't locate Can't locate object method " Useless use of hash element in void context Useless use of private variable in void context readline on closed filehandle in Perl Possible precedence issue with control flow operator Scalar value Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. What should I use for a Perl script's shebang line? Ask Question. Asked 11 years, 6 months ago. Active 1 year, 8 months ago. Viewed 51k times. Which of these is better or faster to use as the shebang line for a Perl script? Improve this question. Kevin Panko 7, 19 19 gold badges 48 48 silver badges 60 60 bronze badges. Anonymous Anonymous 1 1 gold badge 4 4 silver badges 3 3 bronze badges. It needs a full path. Add a comment. Active Oldest Votes.
Improve this answer. Schwern Schwern k 21 21 gold badges silver badges bronze badges. On Unix,! The user logs in as "root". Then when root tries to run a system script, this actually runs the non-system perl.
So system scripts should not use this. Reason to not ever log in as root. Use sudo. Schwern - you forgot one thing - not all user's preferred perl binaries are named perl : [ ours is perl5. DVK You're right, there are minor incompatibilities, and we could nit pick them all day. Now, which is better: not having anything called "perl" in your path and having no chance of running scripts looking for "perl", and having something called "perl" in your path you don't need to be root to put a perl symlink in your path and having a good chance?
Show 30 more comments. Dodgie 9 9 silver badges 17 17 bronze badges. ChristopheD ChristopheD k 27 27 gold badges silver badges bronze badges. A shebang line tells a Unix shell which interpreter to pass the script to. On Unix, the third option full path to perl executable is best. I originally had the first 2 characters in the shebang line reversed.
Community Bot 1 1 1 silver badge.
0コメント