Xref: utzoo comp.sources.d:4292 alt.sources.d:224 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!ateng!chip From: chip@ateng.com (Chip Salzenberg) Newsgroups: comp.sources.d,alt.sources.d Subject: Perl scripts on systems without "#!" Message-ID: <255072E0.20005@ateng.com> Date: 2 Nov 89 17:01:17 GMT References: <1125@kl-cs.UUCP> <2473@convex.UUCP> <14810@bfmny0.UU.NET> <13411@orstcs.CS.ORST.EDU> Organization: A T Engineering, Tampa, FL Lines: 36 [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; or "'Why do we post to Usenet?' Naturally, the answer is, 'To get a response.'" -- Brad "Flame Me" Templeton