bdhond has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Out of Hubris, I'm developing a simple scripting language. The interpreter is a perl program.

This now works by doing

$ interpreter.pl myscript

What I would like to do is, to include as the first line of my script (made executable, of course):

#! /path/to/interpreter.pl

and just run the script itself.

But when I do that, the interpreter never starts, and the shell tries executing the script. This I don't understand, because the shell does not do that when I start the script with

#! cat

In that case, the script is handed to cat perfectly. What is missing in my setup?

This is under Mac OS X Darwin, which is like BSD

Cheers,

Bas

Replies are listed 'Best First'.
•Re: Shebang to a perl program
by merlyn (Sage) on Jan 19, 2003 at 13:50 UTC
    Shebang works only with real binaries, not scripts. You can't nest shebangs.

    You could use PAR to turn your script into an executable, though. It seems to be working even under OS X now.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Shebang to a perl program
by IlyaM (Parson) on Jan 19, 2003 at 13:50 UTC
    I don't know about all Unices but at least on Linux (and it looks on BSD too) you cannot use scripts in shebang line. Only programs in native executable formats which are understood by kernel can be used there.

    As workaround you can try to use

    #!/path/to/perl /path/to/interpreter.pl
    as shebang. Another approach is writing small wrapper in C which launches your Perl program and using this wrapper in shebang.

    --
    Ilya Martynov, ilya@iponweb.net
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
    Personal website - http://martynov.org

Re: Shebang to a perl program
by adrianh (Chancellor) on Jan 19, 2003 at 14:08 UTC

    Another solution is to use HashBang. From the docs:

    This CPAN distribution will install a binary program on your system called 'hashbang'. You can use this program to write your own hashbang style interpreters in Perl.

    CPAN - gotta love it ;-)

      Your replies saved me a lot of time finding out what the problem was, and I now have three ways in which to try to get it to work. Thanks!

      Bas