Perl scripts on systems without "#!"

Chip Salzenberg chip at ateng.com
Fri Nov 3 04:01:17 AEST 1989


[Note the cross-posting; send followups to the appropriate group.]

According to pvo3366 at sapphire.OCE.ORST.EDU (Paul O'Neill):
[Quoting the Perl manual:]
>
>               #!/usr/bin/perl
>               eval "exec /usr/bin/perl -S $0 $*"
>                    if $running_under_some_shell;
>

As the inventor of the "eval exec" hack, I have three comments:

  1.  Some systems don't permit a Bourne shell script to begin with "#".
      Xenix, for example.  When using "eval exec" on a Xenix system, the
      "#!" line must be omitted.

  2.  The "$*" hack is not good.  It's universally available, but it's
      broken in the face of arguments with imbedded spaces or other
      strangeness.  A better choice is "$@", which quotes each argument.
      Due to an old bug in some shells, this must be spelled ${1+"$@"}.

  3.  Larry was a nice guy to add the -S flag just for me.  :-)

Therefore, all Perl scripts on my system begin with these two lines:

    eval 'exec /bin/perl -S $0 ${1+"$@"}'
       if $running_under_some_shell;

I have yet to extend this method in a way that works for the C shell.  If I
could do so, then starting the script with "#!" would work on Xenix.  Does
anyone out there have an idea?
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip at ateng.com> or <uunet!ateng!chip>
"'Why do we post to Usenet?'  Naturally, the answer is, 'To get a response.'"
                        -- Brad "Flame Me" Templeton



More information about the Alt.sources.d mailing list