texlive.combine: fix perl scripts without a shebang

Fixes #24343. These parts of upstream texlive are really ugly.
Also improve variable quoting in the code around.

+9 -3
+9 -3
pkgs/tools/typesetting/tex/texlive/combine.nix
··· 155 --prefix PERL5LIB : "$out/share/texmf/scripts/texlive" 156 157 # avoid using non-nix shebang in $target by calling interpreter 158 - if [[ "$(head -c 2 $target)" = "#!" ]]; then 159 - local cmdline="$(head -n 1 $target | sed 's/^\#\! *//;s/ *$//')" 160 local relative=`basename "$cmdline" | sed 's/^env //' ` 161 local newInterp=`echo "$relative" | cut -d\ -f1` 162 local params=`echo "$relative" | cut -d\ -f2- -s` 163 - local newPath="$(type -P $newInterp)" 164 if [[ -z "$newPath" ]]; then 165 echo " Warning: unknown shebang '$cmdline' in '$target'" 166 continue 167 fi 168 echo " and patching shebang '$cmdline'" 169 sed "s|^exec |exec $newPath $params |" -i "$link" 170 else 171 sed 's|^exec |exec -a "$0" |' -i "$link" 172 echo
··· 155 --prefix PERL5LIB : "$out/share/texmf/scripts/texlive" 156 157 # avoid using non-nix shebang in $target by calling interpreter 158 + if [[ "$(head -c 2 "$target")" = "#!" ]]; then 159 + local cmdline="$(head -n 1 "$target" | sed 's/^\#\! *//;s/ *$//')" 160 local relative=`basename "$cmdline" | sed 's/^env //' ` 161 local newInterp=`echo "$relative" | cut -d\ -f1` 162 local params=`echo "$relative" | cut -d\ -f2- -s` 163 + local newPath="$(type -P "$newInterp")" 164 if [[ -z "$newPath" ]]; then 165 echo " Warning: unknown shebang '$cmdline' in '$target'" 166 continue 167 fi 168 echo " and patching shebang '$cmdline'" 169 sed "s|^exec |exec $newPath $params |" -i "$link" 170 + 171 + elif head -n 1 "$target" | grep -q 'exec perl'; then 172 + # see #24343 for details of the problem 173 + echo " and patching weird perl shebang" 174 + sed "s|^exec |exec '${perl}/bin/perl' -w |" -i "$link" 175 + 176 else 177 sed 's|^exec |exec -a "$0" |' -i "$link" 178 echo