Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^5: shebang anomaly

by Anonymous Monk
on Apr 20, 2018 at 16:51 UTC ( #1213266=note: print w/replies, xml ) Need Help??

in reply to Re^4: shebang anomaly
in thread shebang anomaly

So you want an env that works in a DWIM manner? How should it detect whether it was invoked from command line or from shebang? Note that it is the OS that passes a single argument to env. To rectify this, you'd have to change the way OS behaves.

FWIW, Linux supports custom executable formats (binfmt_misc). You could actually hack up a fancy that is shebang capable, and arrange this to handle your scripts as well. But then you'd have to decide how to parse/split the argument string: just split it at whitespace, or use shell escaping rules? Which shell? All in all, that's a horrible can of worms, which is probably why the shebang is as it is today.

If you absolutely need a perl environment that is predictable and reliable, then the program path is the least of your worries. You'd most likely bundle your own perl and modules in that case, and know the path of your binaries.

Replies are listed 'Best First'.
Re^6: shebang anomaly
by perlboy_emeritus (Sexton) on Apr 20, 2018 at 20:33 UTC
    I appreciate your insights but you're missing the point. I don't intend to reinvent the wheel and write a new shell. What I need and what I want is to execute Perl scripts with the same shebang in either macOS or Linux, or even Windows XP with the help of MKS Toolkit. Why, because I have multiple Perls installed in each OS and multiple OSes and all share the same Perl source. So, I don't want to have to edit scripts originating in macOS with a #! /usr/bin/env perl -w shebang to #! /usr/bin/perl -w just so they run in debian. perlbrew does this now with nothing more than a fairly sophisticated .bashrc. The cmd code I downloaded that choroba pointed me to does almost what I want now. It only omits actually printing the environment but that is trivial to fix. Whenever this cmd/env is called without any arguments it can print the environment, the %ENV hash. So, you seem to be hinting that Linux is less capable than macOS (just another *NIX), and/or the maintainers of GNU coreutils are incapable of doing or unwilling to do what Apple engineers did and can do? Why do you think this works in macOS and not Linux, other than the maintainers of env don't want to do it? Are fork and exec in Darwin different from their counterparts in Linux? Or BSD, or AIX, or Next, or any other UNIX or UNIX-like OS?

      Why do you think this works in macOS and not Linux

      Because the shell used to parse and execute the shebang line is different in each of those.

        I think you want to replace "shell" with "kernel". I suppose it could be in libc, but I'm certain it's not in /bin/sh, except for cygwin.
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-10-26 14:24 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (251 votes). Check out past polls.