On Wed, Sep 12, 2007 at 12:08:48AM +0400, Alexey I. Froloff wrote: > * Alexey Tourbin [070911 23:46]: > > #!/bin/sh > > exec perl -w -x $0 ${1+"$@"} # -*- mode: perl; perl-indent-level: 2; -*- > > #!perl -w > Я где-то видел офигенно портабельный перловый шебанг, который > работает на всех-всех-всех платформах с любым sh и perl. > Занимает он 12 строк. Этот вроде сделал. Всякую фигню maintainer'ы пакуют а мне страдай! commit 05cd09ba0f8559f835ac770946d673fb4ad887c0 Author: Alexey Tourbin Date: Wed Sep 12 01:32:35 2007 +0400 perl.req: implemented support for "perl -x" re-exec hack (fixes cvs2cl.pl) $ head -3 cvs2cl.pl #!/bin/sh exec perl -w -x $0 ${1+"$@"} # -*- mode: perl; perl-indent-level: 2; -*- #!perl -wT $ ./perl.req cvs2cl.pl /home/at/git.alt/rpm-build-perl/cvs2cl.pl syntax OK perl(File/Basename.pm) perl(Text/Wrap.pm) perl(Time/Local.pm) $ diff --git a/perl.req b/perl.req index 1285d2a..485e9c9 100755 --- a/perl.req +++ b/perl.req @@ -117,17 +117,35 @@ bad: sub shebang_options { my $fname = shift; open my $fh, $fname or die "$0: $fname: $!\n"; - my $shebang = <$fh>; - chomp $shebang; + local $_ = <$fh>; my @argv; - if ($shebang =~ s/^#!\s*\S*perl\S*\s*// && $shebang) { - local $_ = $shebang; + if (s/^#!\s*\S*perl\S*//) { foreach my $arg (split) { last if $arg =~ /^#/; next if $arg eq "--"; push @argv, $arg; } } + elsif (m[^#!\s*/bin/sh(\s|$)]) { + # check for "perl -x" re-exec hack + my $maybe_x; + while (<$fh>) { + # this is just a standard way to re-exec perl: + last if /^eval\s+'exec\s/; + if (/\bexec\s.*\bperl.*\s-x/) { + $maybe_x = 1; + } + elsif ($maybe_x and s/^#!\s*\S*perl\S*//) { + push @argv, "-x"; + foreach my $arg (split) { + last if $arg =~ /^#/; + next if $arg eq "--"; + push @argv, $arg; + } + last; + } + } + } return @argv; }