Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perlrun #!/bin/sh incantation n.g. 4 linux #7699

Closed
p5pRT opened this issue Dec 9, 2004 · 7 comments
Closed

perlrun #!/bin/sh incantation n.g. 4 linux #7699

p5pRT opened this issue Dec 9, 2004 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 9, 2004

Migrated from rt.perl.org#32979 (status was 'resolved')

Searchable as RT32979$

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2004

From brucer@cisco.com

Created by brucer@iceage.cisco.com

perlrun incantation​:

#!/bin/sh -- # -*- perl -*- -p
eval 'exec perl -wS $0 ${1+"$@​"}'
if $running_under_some_shell;

does not work

What does work is​:

#!/bin/sh
#! -*- perl -*-
eval 'exec perl -x -wS $0 ${1+"$@​"}'
if 0;

found at http​://lists.gnu.org/archive/html/bug-bash/2001-07/msg00070.html

This works on both solaris2.8 (ours anyway) and linux

thanks,
Bruce

Perl Info

Flags:
    category=docs
    severity=high

Site configuration information for perl v5.8.6:

Configured by brucer at Wed Dec  8 14:09:34 PST 2004.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos iceage 5.8 generic_108528-27 sun4u sparc sunw,sun-fire-880 '
    config_args='-Dcc=gcc -Dprefix=/auto/gsg-sw/inst/sparc-sun-solaris2.8 -Dman1dir=/auto/gsg-sw/inst/share/man/man1 -Dman3dir=/auto/gsg-sw/inst/share/man/man3 -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.4.2', gccosandvers='solaris2.8'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.6:
    /auto/gsg-sw/inst/sparc-sun-solaris2.8/lib/perl5/5.8.6/sun4-solaris
    /auto/gsg-sw/inst/sparc-sun-solaris2.8/lib/perl5/5.8.6
    /auto/gsg-sw/inst/sparc-sun-solaris2.8/lib/perl5/site_perl/5.8.6/sun4-solaris
    /auto/gsg-sw/inst/sparc-sun-solaris2.8/lib/perl5/site_perl/5.8.6
    /auto/gsg-sw/inst/sparc-sun-solaris2.8/lib/perl5/site_perl
    .


Environment for perl v5.8.6:
    HOME=/users/brucer
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib:
    LOGDIR (unset)
    PATH=.:/users/brucer/sparc-sun-solaris2.8/bin:/auto/gsg-sw/inst/sparc-sun-solaris2.8/bin:/usr/java/j2re1.4.1_01/bin:/users/brucer/share/bin:/auto/gsg-sw/inst/share/bin:/router/bin:/usr/local/packages/atria/current/contrib:/sw/current/solaris2bin:/usr/local/bin:/usr/atria/bin:/nfs/ddts/ddtshome/bin:/bin:/usr/bin:/auto/gsg-sw/inst/share/bin:/auto/gsg-sw/share/bin:/auto/gsg-sw/inst/solaris/bin:/auto/gsg-sw/share:/auto/gsg-sw/linuxbin:/auto/gsg-tools/frame/current/bin:.:/users/brucer/sparc-sun-solaris2.8/bin:/usr/java/j2re1.4.1_01/bin:/users/brucer/share/bin:/auto/gsg-sw/inst/share/bin:/router/bin:/usr/local/packages/atria/current/contrib:/sw/current/solaris2bin:/usr/local/bin:/usr/atria/bin:/nfs/ddts/ddtshome/bin:/bin:/usr/bin:/auto/gsg-sw/inst/share/bin:/auto/gsg-sw/share/bin:/auto/gsg-sw/inst/solaris/bin:/auto/gsg-sw/share:/auto/gsg-sw/linuxbin:/auto/gsg-tools/frame/current/bin:/opt/ECSossh/bin:/usr/bin:/usr/sbin:/usr/openwin/bin:/usr/local/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 21, 2004

From @smpeters

[brucer@​cisco.com - Thu Dec 09 11​:41​:30 2004]​:

This is a bug report for perl from brucer@​iceage.cisco.com,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]
perlrun incantation​:

#!/bin/sh -- # -*- perl -*- -p
eval 'exec perl -wS $0 ${1+"$@​"}'
if $running_under_some_shell;

does not work

What does work is​:

#!/bin/sh
#! -*- perl -*-
eval 'exec perl -x -wS $0 ${1+"$@​"}'
if 0;

found at http​://lists.gnu.org/archive/html/bug-bash/2001-
07/msg00070.html

This works on both solaris2.8 (ours anyway) and linux

thanks,
Bruce

The following patch to perlrun.pod applies the change suggested above.

Inline Patch
--- perlrun.pod.orig    Tue Dec 21 11:32:41 2004
+++ perlrun.pod Tue Dec 21 11:34:34 2004
@@ -79,9 +79,10 @@
 The sequences "-*" and "- " are specifically ignored so that you could,
 if you were so inclined, say

-    #!/bin/sh -- # -*- perl -*- -p
-    eval 'exec perl -wS $0 ${1+"$@"}'
-        if $running_under_some_shell;
+    #!/bin/sh
+    #! -*-perl-*-
+    eval 'exec perl -x -wS $0 ${1+"$@"}'
+        if 0;

@p5pRT
Copy link
Author

p5pRT commented Dec 21, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2008

From @smpeters

On Tue Dec 21 09​:36​:12 2004, stmpeters wrote​:

[brucer@​cisco.com - Thu Dec 09 11​:41​:30 2004]​:

This is a bug report for perl from brucer@​iceage.cisco.com,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]
perlrun incantation​:

#!/bin/sh -- # -*- perl -*- -p
eval 'exec perl -wS $0 ${1+"$@​"}'
if $running_under_some_shell;

does not work

What does work is​:

#!/bin/sh
#! -*- perl -*-
eval 'exec perl -x -wS $0 ${1+"$@​"}'
if 0;

found at http​://lists.gnu.org/archive/html/bug-bash/2001-
07/msg00070.html

This works on both solaris2.8 (ours anyway) and linux

thanks,
Bruce

The following patch to perlrun.pod applies the change suggested above.

--- perlrun.pod.orig Tue Dec 21 11​:32​:41 2004
+++ perlrun.pod Tue Dec 21 11​:34​:34 2004
@​@​ -79,9 +79,10 @​@​
The sequences "-*" and "- " are specifically ignored so that you could,
if you were so inclined, say

- #!/bin/sh -- # -*- perl -*- -p
- eval 'exec perl -wS $0 ${1+"$@​"}'
- if $running_under_some_shell;
+ #!/bin/sh
+ #! -*-perl-*-
+ eval 'exec perl -x -wS $0 ${1+"$@​"}'
+ if 0;

Thanks! Applied as change #34943.

Steve Peters

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2008

@smpeters - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Nov 27, 2008
@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2008

From @gbarr

On Nov 26, 2008, at 11​:52 PM, Steve Peters via RT wrote​:

The following patch to perlrun.pod applies the change suggested
above.

--- perlrun.pod.orig Tue Dec 21 11​:32​:41 2004
+++ perlrun.pod Tue Dec 21 11​:34​:34 2004
@​@​ -79,9 +79,10 @​@​
The sequences "-*" and "- " are specifically ignored so that you
could,
if you were so inclined, say

- #!/bin/sh -- # -*- perl -*- -p
- eval 'exec perl -wS $0 ${1+"$@​"}'
- if $running_under_some_shell;
+ #!/bin/sh
+ #! -*-perl-*-
+ eval 'exec perl -x -wS $0 ${1+"$@​"}'
+ if 0;

It should be pointed out that a caveat of using -x is that line
numbers as reported by perl will no longer reflect the line counting
from the first line in the file, but instead counting from the #! -*-
perl-*-. This can confuse people, eg

#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -wS $0 ${1+"$@​"}'
  if 0;
die "x";

gives​:
x at /tmp/foo line 4.

But the die is on line 5. This offset will grow if more comments, or
shell code, are placed before the #!perl line
This can be manually resolved with a #line directive

#!/bin/sh
#! -*-perl-*-
#line 4
eval 'exec perl -x -wS $0 ${1+"$@​"}'
  if 0;
die "x";

gives​:
x at /tmp/foo line 6.

Graham.

@p5pRT
Copy link
Author

p5pRT commented Dec 4, 2008

From dscoular@gmail.com

Hi Graham,

On Thu Nov 27 14​:46​:34 2008, gbarr wrote​:

But the die is on line 5. This offset will grow if more comments, or
shell code, are placed before the #!perl line
This can be manually resolved with a #line directive

#!/bin/sh
#! -*-perl-*-
#line 4
eval 'exec perl -x -wS $0 ${1+"$@​"}'
if 0;
die "x";

gives​:
x at /tmp/foo line 6.

Graham.

This is almost perfect with the one drawback that I have to remember
to invoke the perl debugger with -x too.

perl -dx test.pl

Otherwise I get the following​:

[dscoular@​prestwick projects]$ perl -d magic.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

/bin/sh​: -d​: invalid option
Usage​: /bin/sh [GNU long option] [option] ...
  /bin/sh [GNU long option] [option] script-file ...
GNU long options​:
  --debug
  --debugger
  --dump-po-strings
  --dump-strings
  --help
  --init-file
  --login
  --noediting
  --noprofile
  --norc
  --posix
  --protected
  --rcfile
  --rpm-requires
  --restricted
  --verbose
  --version
  --wordexp
Shell options​:
  -irsD or -c command or -O shopt_option (invocation only)
  -abefhkmnptuvxBCHP or -o option

I couldn't think of a nicer way to automate this and I could
see no way of getting xemacs' perldb to add the -x flag.

It would be great if your comment could make it into the perlrun doco.

Cheers,

Doug

--
"The big print giveth and the small print taketh away".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant