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

Hi.

One day my shebang suddenly stopped working properly.

It doesn't complain that it can't find perl or anything.

It just doesn't do anything at all.

Can anyone guide me to what is wrong here?

Thanks a lot.

[miraceti@centenum blast]$ [miraceti@centenum blast]$ which perl /usr/bin/perl [miraceti@centenum blast]$ cat hello.pl #!/usr/bin/perl -W print "Hello, World!\n"; [miraceti@centenum blast]$ ./hello.pl [miraceti@centenum blast]$ perl hello.pl Hello, World! [miraceti@centenum blast]$

2006-04-14 Retitled by planetscape, as per Monastery guidelines
Original title: '(dupe of 543444; do not reply) problem with shebang'

Edited by planetscape - added code tags and rudimentary formatting

Replies are listed 'Best First'.
Re: problem with shebang
by TimToady (Parson) on Apr 15, 2006 at 05:50 UTC
    Here's another tack. Run this command, and you should get the # and the ! as output
    $ od -c -N2 hello.pl 0000000 # !
    If you don't, then there's some kind of whitespace or other invisible character (a BOM maybe) before the #!, and that's what is hiding the shebang from the operating system.

      Interesting, TimToady, I didn't know the od command:

      $ od -c -N2 1.hello.pl 0000000 # ! 0000002 $ man od $ od -c -N8 1.hello.pl 0000000 # ! / u s r / b 0000010 $
Re: problem with shebang
by TimToady (Parson) on Apr 14, 2006 at 22:58 UTC
    It's hard to tell with the formatting, but is it possible that your shebang isn't the first line of the file? If it's on the second line, it's just a comment, and your program is being fed to some other interpreter than Perl.
Re: problem with shebang
by chromatic (Archbishop) on Apr 14, 2006 at 22:18 UTC

    I bet perl isn't /usr/bin/perl and which perl will reveal more information.

    Re-parented to non-reaped dupe by planetscape

Re: problem with shebang
by ww (Archbishop) on Apr 14, 2006 at 22:18 UTC

    1) You can edit errors such as you made here (by failing to include code tags) by updating (adding code tags) rather than by duping the question, as you did in id:/543444. Please update, rather than creating a new question, in the future. On the other hand, until we fix the the dupe situationdone please see chromatic's response to your other post, in case you're showing us historical output: did you reinstall or update perl recently?

    2) If the your illustration is not suffering from fatfingers or editing, what is not working? I see cat spitting out plausible code with a perfectly fine shebang --
    #!/usr/bin/perl -W
    ... and execution of hello.pl emitting what I would expect from your code.

      thanks for editting my post.
      it works when i use 'perl' explicitly in front of script name,
      but it doesn't work when i just type './hello.pl'.

      './hello.pl' spits out nothing.
      'perl hello.pl' works.

      i have upgraded the kernel recently.
      but not the perl.

        OTOH, I see you also posted the exact same question to clpmisc. If anything relevant and different from what comes out here pops up there, then be sure to report for the benefit of others, and vice-versa.
Re: problem with shebang
by zentara (Cardinal) on Apr 15, 2006 at 11:23 UTC
    Nobody has mentioned the other major cause of this symptom, dos line endings. If I do a unix2dos conversion on one of my scripts, it will have the same symptoms as you describe......
    1. will not run from shebang 2. will run with "perl myscript" 3. will look fine with "cat myscript".
    Try running dos2unix on your script. Or look for control-M characters as line endings in your editor. MC's mcedit shows them.

    I'm not really a human, but I play one on earth. flash japh
      Actually, because of the -W, it would work with CRs:
      $ od -c 543561.pl 0000000 # ! / u s r / b i n / p e r l 0000020 - W \r \n \r \n p r i n t " H e l 0000040 l o , W o r l d ! \ n " ; \r \n 0000060 $ 543561.pl Hello, World!
Re: problem with shebang
by bradcathey (Prior) on Apr 14, 2006 at 22:50 UTC

    I've had problems when I copied a shebang over from another file and that contained gremlins (entities not supported by Perl). For what it's worth.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      if this is a unix platform type
      whereis perl
      into the prompt. it'll tell you all your perl locations located in your $PATH
Re: problem with shebang
by apotheon (Deacon) on Apr 15, 2006 at 07:47 UTC

    Did you make the file executable?

    I would expect an error message if not, but it's worth checking anyway.

    There's also the possibility that your perl executable might have been corrupted somehow. Try replacing the perl executable somehow — perhaps by "updating" the software using whatever software management system is standard for your OS.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin

Re: problem with shebang
by miraceti (Initiate) on Apr 15, 2006 at 22:16 UTC
    the problem was with selinux.
    When I turned off selinux.
    the problem went away.

    I haven't found out exactly what is causing the problem.
    But it wasn't something with perl.
    thanks for all the comments.
Re: problem with shebang
by ikegami (Patriarch) on Apr 15, 2006 at 04:53 UTC

    I don't know if that's problem, but shouldn't that be -w instead of -W?

    Also, what OS are you using? Windows has issues running .pl's directly, although I think the problems might be limited to in/out redirection. (See pl2bat.)

    Update: Apparently, -W is a valid option. I should have checked first.

Re: problem with shebang
by spiritway (Vicar) on Apr 15, 2006 at 05:19 UTC

    I'm reaching here, but another possibility is to type type perl at the command line, which will give you a bit more information than which perl. In particular, it will let you know if your perl is a link to another location (it may say something like, 'perl is hashed').

    You may want to check your $PATH, which might give you a hint about what's going on, or where things are being looked for. You might also check your .profile and .bashrc (or whatever the corresponding files would be for your setup), to see whether something in them has been changed.

Re: problem with shebang
by jcoxen (Deacon) on Apr 15, 2006 at 12:50 UTC
    Try
    chmod +x hello.pl
    From your output, it looks like the hello.pl file is not executable.

    Jack

      Note that Kate has a BOM option that, if checked, adds a BOM mark as the first three characters in the file. They doesn't show in Kate or Vim. You can see them with a hex editor (like Bless) as "EF BB BF" ("..." in the character section). I was stumped before I found this out and I've no idea how this option came to be checked in my case. On top of that Bless couldn't save a changed file due to "Not enough space on device bla bla..." which in it's turn was fixed by entering "/tmp" under "Edit","Preferences". A problem never comes alone.