LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2013, 09:25 AM   #1
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Rep: Reputation: 0
issues running a perl script


Afternoon,

hoping someone might be able to suggest a possible reason for my problem and perhaps a solution as well.

i'm using Red Hat Enterprise, Linux Server 5.3.

I've got a perl script that runs as expected when invoked with the perl command, but
doesn't run when I specify #!/usr/bin/perl at the top of the file and attempt to run the script without the perl command.

the command whereis perl returns /usr/bin/perl, so I'm not sure why the script wouldn't run using the she-bang.

It's not script permissions, so I'm a bit stumped as to the cause of this.

any ideas?

TIA,

DanishGambit.
 
Old 04-16-2013, 09:41 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Have you got errors in the script such as DOS-style line endings?

Is the script on a filesystem mounted noexec?
 
Old 04-16-2013, 09:49 AM   #3
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
thanks for the prompt response - no errors on the script itself - as mentioned it runs fine when the script is invoked with the perl command, it's only when I try to rely on the she-bang that it doesn't run.

No, I presume it's not because other non-perl scripts run fine.
 
Old 04-16-2013, 09:50 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
What error messages do you see?
 
Old 04-16-2013, 09:57 AM   #5
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
when I run it with the perl command, no errors, runs fine.

but when I put the sh-bang at the start of the file, i.e. #!/usr/bin/perl, it returns errors:

-bash: =: command not found
-bash: print: command not found

it's almost like it's ignoring the sh-bang.
 
Old 04-16-2013, 10:01 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by danishgambit View Post
it's almost like it's ignoring the sh-bang.
Perhaps you saved the file as UTF? Try to make sure that it's in ASCII form.

And you don't use bash to run the file do you?
Code:
bash perl.pl
 
Old 04-16-2013, 10:10 AM   #7
Ginola
Member
 
Registered: Sep 2012
Location: London
Distribution: CentOS, RHEL, Ubuntu
Posts: 73

Rep: Reputation: Disabled
what do these return?

Code:
which perl
Code:
file <your perl file name>

Last edited by Ginola; 04-16-2013 at 10:14 AM.
 
Old 04-16-2013, 10:15 AM   #8
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
no, it's ascii. I don't explicitly run the script with bash, but bash is set as the default shell (the environment variable $SHELL is set to /bin/bash

Cheers,

DanishGambit.
 
Old 04-16-2013, 10:18 AM   #9
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
Ginola,

which perl returns /usr/bin/perl

and file myfile.pl returns

perl script text executable
 
Old 04-16-2013, 10:24 AM   #10
Ginola
Member
 
Registered: Sep 2012
Location: London
Distribution: CentOS, RHEL, Ubuntu
Posts: 73

Rep: Reputation: Disabled
Can you post the first ten lines of code?

Code:
head -10 myfile.pl
 
Old 04-16-2013, 10:26 AM   #11
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
And might as well be
Code:
hexdump -C myfile.pl | head -n 10
 
1 members found this post helpful.
Old 04-16-2013, 10:34 AM   #12
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
Hi Ginola,

even the simple script has the same issue

#!/usr/bin/perl
# this should be working

print "work, dammit, work!!\n";

the hexdump shows

00000000 23 21 2f 75 73 72 2f 62 69 6e 2f 70 65 72 6c 0a |#!/usr/bin/perl.|
00000010 23 20 2d 20 73 68 6f 75 6c 64 20 62 65 20 77 6f |# - should be wo|
00000020 72 6b 69 6e 67 0a 0a 70 72 69 6e 74 20 22 57 6f |rking..print "Wo|
00000030 72 6b 2c 20 64 61 6d 6e 20 79 6f 75 2c 20 77 6f |rk, damn you, wo|
00000040 72 6b 21 21 5c 6e 22 3b 0a 0a |rk!!\n";..|
0000004a
 
Old 04-16-2013, 10:41 AM   #13
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Well that seems normal. I wonder if your /usr/bin/perl is actually a bash script.

I ran your script and it has no problem with me.
 
Old 04-16-2013, 10:46 AM   #14
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
cheers, thanks for your time.

DanishGambit.
 
Old 04-16-2013, 12:02 PM   #15
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
What is the name of the file? It isn't conflicting with some other filename in the system, especially soemthing found in $PATH, is it? Any alias conflict? Are you executing the specific filespec, or assuming your script is found in $PATH somewhere?
--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OTRS issues while running apache2-perl-startup.pl script linuxlover.chaitanya Linux - Newbie 9 11-28-2011 11:10 PM
why this script is running in bash but not in perl ratul_11 Linux - General 2 08-17-2007 09:31 AM
Running a perl script bobfinners Linux - Software 1 06-23-2005 05:18 PM
running perl script dav_y2k Linux - Newbie 3 04-25-2005 05:00 AM
Running Perl Script upon startup andy7t Linux - Software 1 04-20-2005 04:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration