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

In this node, I asked about running perl on multiple platforms. I compiled binaries for all three platforms, but now I'm having trouble with the shell script to run the correct one. I tried jsegal's suggestion, and running the shell script executes perl correctly, but executing a perl script with a shebang line pointing to the shell script tries to execute it with the shell rather than perl. Any suggestions?

Replies are listed 'Best First'.
Re: More multiplatform perl
by jjdraco (Scribe) on Nov 15, 2002 at 02:55 UTC
    I'm sorry, could you rephrase that. That didn't make any sences to me. I just tried using jsegal's suggestion and it worked for me.

    jjdraco
    learning Perl one statement at a time.
      If I type in 'perl' from the shell, it executes the correct version. If I run a script with a shebang line that points to perl, it attempts to execute the perl script with ksh instead of executing the perl binary.
        Have you done the unix command  chmod +x on the file that stores the perl script with the shebang line?
        so if you tried
        #!/usr/bin/perl use strict; use warnings; print "Hello World!!\n\n"
        it would try and run ksh? assuming perl is in /usr/bin/perl I'm no expert but that sounds like a problem with your system setup somewhere. its the system that looks at the shebang line and decides what to run. if its calling ksh then...I don't have a clue.


        jjdraco
        learning Perl one statement at a time.
Re: More multiplatform perl
by jsegal (Friar) on Nov 15, 2002 at 15:30 UTC
    Could you post your test script?
    I've tried a couple of variants of this, and can't seem to emulate your problem. (i.e. it usually works). One thing -- don't try
    #!~/bin/perl # This won't work (at least not portably) because of the ~ on the #shebang line... use #!/my/home/directory/bin/perl instead print "Your perl code here...\n"
    As the tilde-expansion is something done by a shell, not by the OS (and what happens when a different user runs the script...?).
    I doubt you are doing this (as you would probably get a "no such file or directory" error instead of the behavior you are seeing), but it is a warning to any other readers, too...

    --JAS
      I am putting the full path to perl in the shebang line.

      At first, since the wrapper script had /bin/ksh in the shebang line, I assumed that the this was getting executed with the perl script I was trying to run. However, I tried changing #!/bin/ksh to #!/my/home/dir/perl/bin/perl5.8.0-IRIX64 in the wrapper script, but any perl scripts I ran *still* executed with ksh, which leads me to believe it's a problem with the system, not the way I set it up. Since perl/bin/perl is a text file, not a binary, would the system assume it isn't a valid interpreter and try to execute perl scripts with the shell?
        Hmm.
        What should be happening is this:
        1. You try to execute "myperlscript", which is an executable file, which begins with #!/path/to/my/perl.
        2. The system sees that the file begins with #!/path/to/my/perl, and executes /path/to/my/perl with the full path the script as the first argument (and any additional command line arguments will follow)
        3. The /path/to/my/perl program (the ksh script) is another text file -- the OS opens this up, sees that it should run /bin/ksh (from the first line), and effectively runs  /bin/ksh /path/to/my/perl myperlscript <args>
        4. Now /path/to/my/perl is executed, and its last line is exec /path/to/proper/perl "$@", so it executes /path/to/proper/perl myperlscript <args>
        5. perl takes over from here and runs your script...
        If your perl script is being executed via ksh, that sounds to me like your wrapper script has an error of some sort -- the wrapper script should be explicitly executing perl on your perl script.
        If you post your sample scripts (your perl wrapper and your sample perl script) that will help us diagnose what is happening...

        --JAS