Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Can I write a transparent shell wrapper to start the correct build of Perl?

by Porculus (Hermit)
on Feb 05, 2008 at 19:52 UTC ( [id://666390]=note: print w/replies, xml ) Need Help??


in reply to Can I write a transparent shell wrapper to start the correct build of Perl?

If "the user environment is automatically set up so that the correct perl for their host is in the path", why don't you just use #!/usr/bin/env perl...?
  • Comment on Re: Can I write a transparent shell wrapper to start the correct build of Perl?
  • Download Code

Replies are listed 'Best First'.
Re^2: Can I write a transparent shell wrapper to start the correct build of Perl?
by almut (Canon) on Feb 05, 2008 at 21:10 UTC

    There's a potential subtle problem with using env, which is that you typically can't pass arguments to the perl binary this way, like for example

    #!/usr/bin/env perl -w

    On my Debian Linux this produces

    $ ./666330.pl /usr/bin/env: perl -w: No such file or directory

    This is not a problem with env (running /usr/bin/env perl -w 666330.pl from the command line would work fine...), but rather with many Unix kernels, which treat everything after the interpreter specified on the shebang line (here /usr/bin/env) as a single argument, i.e. it would pass "perl -w" to /usr/bin/env as the program name to execute... which of course doesn't exist. This can easily be seen with strace:

    $ strace -e trace=execve ./666330.pl execve("./666330.pl", ["./666330.pl"], [/* 24 vars */]) = 0 execve("/home/almut/bin/perl -w", ["perl -w", "./666330.pl"], [/* 24 v +ars */]) = -1 ENOENT (No such file or directory) execve("/usr/local/bin/perl -w", ["perl -w", "./666330.pl"], [/* 24 va +rs */]) = -1 ENOENT (No such file or directory) execve("/usr/bin/perl -w", ["perl -w", "./666330.pl"], [/* 24 vars */] +) = -1 ENOENT (No such file or directory) execve("/bin/perl -w", ["perl -w", "./666330.pl"], [/* 24 vars */]) = +-1 ENOENT (No such file or directory) execve("/usr/bin/X11/perl -w", ["perl -w", "./666330.pl"], [/* 24 vars + */]) = -1 ENOENT (No such file or directory) /usr/bin/env: perl -w: No such file or directory
      I fixed builds that attempted to use the -w option when calling perl. The shell was treating it as a single command name rather than a command with a switch. The easy way to fix this would be to do something similar to: ln -s ./perl 'perl -w' This will create a symbolic link named 'perl -w' allowing the build to work, in my case. I was running into this with trying to compile the library pango and it was annoying me, because I couldn't figure out where env was calling for the file 'perl -w' to change it. The -w switch only enables some additional warnings, so not entirely necessary. Another option might be to create a script named 'perl -w' then have it call perl with the -w switch.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://666390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found