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

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

Replies are listed 'Best First'.
Re: Can I write a transparent shell wrapper to start the correct build of Perl?
by Anonymous Monk on Jun 25, 2008 at 17:02 UTC
    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.