chip@ateng.com (Chip Salzenberg) (11/03/89)
[Note the cross-posting; send followups to the appropriate group.] According to pvo3366@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@ateng.com> or <uunet!ateng!chip> "'Why do we post to Usenet?' Naturally, the answer is, 'To get a response.'" -- Brad "Flame Me" Templeton
tneff@bfmny0.UU.NET (Tom Neff) (11/03/89)
In article <255072E0.20005@ateng.com> chip@ateng.com (Chip Salzenberg) writes: >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? According to my notes, CSH looks for a colon ':' as the first token in a script and passes it on to /bin/sh if the colon is seen. So perhaps : eval 'exec /bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; would do the trick. But the problem here is that PERL hates the colon! So you could set up a script like this for script execution, but not feed it to perl unmodified. Perl being still under modification, perhaps it could be fixed to accept this. Or is there a clever perl-ism that would let us put the colon there. -- I'm a Leo. Leos don't believe * * * Tom Neff in this astrology stuff. * * * tneff@bfmny0.UU.NET