[tex-live] Re: TeX Live UNIX shell scripts

Harald Hanche-Olsen hanche@math.ntnu.no
Wed, 17 Apr 2002 17:34:17 +0200


Er, if I may break into this thread with a different, but related
topic...  It concerns these perl scripts:

; file * | grep ASCII
e2pall:                   ASCII English text
epstopdf:                 ASCII English text
texdoctk:                 ASCII English text
texi2html:                ASCII English text
thumbpdf:                 ASCII English text

They all start with the line

eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $
argv:q'

which is an old but unfortunately somewhat broken perl-ism.  E.g.,

; ./epstopdf
./epstopdf: Exec format error

The hack relies on some exec hack which tries /bin/sh on a file if
regular exec fails.  The exact details elude me, but portable it is
not.  It will typically fail if a program tries to run the script
using a plain old exec, rather than, e.g., the system() call.
Admittedly my shell may not be widely used (I use es), but this
problem could bite anyone who tries to run these scripts from other
programs.

It might be considered heresy to suggest a python solution to a perl
problem, but the following hack seems to be very portable:

#!/usr/bin/env perl

(Well, it is not a python solution per se, but it came from the python
community, and so might be frowned upon by perl hackers.)  It is a
lucky accident that every system seems to have the env program in the
same place, hence the portability of this hack.

- Harald