[tlbuild] Broken shebangs in TeX Live scripts

Reinhard Kotucha reinhard.kotucha at gmx.de
Sun Apr 10 02:19:13 CEST 2022


On 2022-04-09 at 15:56:16 +0200, Henri Menke wrote:

 > [...]
 > There is however one downside to this approach. The shebang (which is a
 > kernel feature) will only ever pass on the first argument to the
 > executable, so converting
 >
 > #!/usr/bin/perl -w => #!/usr/bin/env perl -w
 >
 > will silently drop the "-w". At the same time I believe that things
 > like warning should be enable on the language level rather than trying
 > to inject commands into the invocation, because if a user runs "perl
 > script.pl" instead of "./script.pl" the warning will also be stripped.

Hi Henri,
the solution for Perl is

   #!/usr/bin/env perl

   BEGIN { $^W = 1; }

BEGIN is evaluated before the script is parsed and compiled, hence the
behavior is comparable with the command-line switch.  The TL installer
and tlmgr are already using this mechanism and probably some other
Perl scripts in TeX Live, too.

BTW, if you compiled a newer version of Perl yourself it will end up
in /usr/local/bin and will only be found by /usr/bin/env.  This is
often necessary if you're using an enterprise edition of Linux. Thus
using /usr/bin/env is by far the best solution.

I'm glad that you didn't find a script with #!/usr/local/bin/perl
which was quite common 20 years ago.

Python's -O switch enables optimization and certainly must be
activated before the script is compiled.  Unless Python provides
something like Perl's BEGIN there is probably no way to use
/usr/bin/env if optimization is absolutely unavoidable.

As far as /bin/bash is concerned, some scripts use non-POSIX Bash
extensions and thus definitely require Bash.  If in doubt, Debian
provides a script "checkbashisms" (part of devscripts).

Thus replacing #!/bin/bash by #!/bin/sh without further investigation
and extensive testing is not possible.

Is it difficult to install Bash on the systems you mentioned?  Are
there package managers available which allow installation of free
software as easily as on Linux?

Regards,
  Reinhard

--
------------------------------------------------------------------
Reinhard Kotucha                            Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                    mailto:reinhard.kotucha at gmx.de
------------------------------------------------------------------



More information about the tlbuild mailing list.