From: Paul D. Smith (pausmith@nortelnetworks.com) Subject: Execing perl? Newsgroups: gnu.bash.bug Date: 2001-07-11 11:55:16 PST OK, this isn't a bug, and it's also something that you'd _think_ would be so obvious it'd be right at the top of all the FAQs, etc... but I can't find it, nor can I figure it out. The Perl docs (perlrun) say you can use this stanza to write a perl script when you don't know where the perl runtime will be; something like: #!/bin/sh -- # -*- perl -*- eval 'exec perl -wS $0 ${1+"$@"}' if $running_under_some_shell; This doesn't work if bash is /bin/sh; I get this error: /bin/sh: -- # -*-perl-*-: unrecognized option (ditto if I use /bin/bash instead). This does work with other Bourne shells, though, such as Solaris' /bin/sh. If I leave out the -- and just use the comment, I get this error: # -*-perl-*-: # -*-perl-*-: No such file or directory (it doesn't ignore the comment). Even moving this past the "normal" 32-char boundary doesn't help. However, if I remove the extra stuff from the first line, then _Perl_ screws up, due to this little gem (from perlrun): If the #! line does not contain the word "perl", the pro- gram named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps peo- ple on machines that don't do #!, because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them. As a result, /bin/sh runs Perl, which turns right around and tries to run /bin/sh, I guess with the options it got (-wS etc. etc.) and I get this: /bin/sh: -w: unrecognized option _Surely_ someone has solved this problem! -- ------------------------------------------------------------------------------- Paul D. Smith HASMAT--HA Software Methods & Tools "Please remain calm...I may be mad, but I am a professional." --Mad Scientist ------------------------------------------------------------------------------- These are my opinions---Nortel Networks takes no responsibility for them.