tags:

views:

493

answers:

5

Maybe it's dumbest question in the world, but I seriously have problems with it and could use help. I am trying to run perl script on linux. It's a simple text editing script, nothing fancy. I googled for it and I found that I had to chmod +x it and then just run myscript.pl in the console. Since it's supposed to modify a text file I did myscript.pl > myfile.txt after chmoding it

But it doesn't work. I get: bash: perl myscript.pl: command not found

+2  A: 

It doesn't look like perl is installed on your Linux machine. Do you get the same thing when you try this: # perl -e 'print "hi";' ?

BryanD
it prints hi ;)
Nii
Okay, cool then that means that Chirael has the right answer. The script just has a bad path to the perl executable in it.
BryanD
+4  A: 

Unless myscript.pl is in your path you will need to specify the current directory.

$ ./myscript.pl

You can check if the current directory is in your path with $ echo $PATH. If you're frequently using this script you can put it in the path by moving it to a directory that's part of your path, usually ~/bin.

Or by adding the current directory to the $PATH environment variable. Check the documentation for your shell for instructions.

EmFi
Explanation: Linux machines have an environment variable set called the `PATH` that has a list of directories to look in for commands. You need to use the dot-slash to tell it to look in the current directory for the file to run.
Rupert Nash
The problem in this answer does not match the error message produced.
Ether
@Ether, looks like you might be right. But Bash usually doesn't give arguments in a error. It's weird that error prints the arguments. Could be that perl isn't in the path, but that doesn't match the error either.
EmFi
"Bash usually doesn't give arguments in a error.". Right. Which makes me think that somehow this was called (including the quotes): `'perl myscript.pl'`.
innaM
@Manni That's got to be it. Not entirely infeasible for someone just following a tutorial.
EmFi
+4  A: 

Can you post the first few lines of your script?

Specifically, if you have #!/usr/bin/perl are there any typos on that line, extra spaces, etc.?

Also do a ls /usr/bin/perl (or whatever is on that line) to make sure it's actually there.

Chirael
Also, if /usr/bin/perl is there (or whatever the path is), as revealed by ls, consider deleting the entire line and re-typing it. It's a long shot, but "invisible characters" are a rare but subtle and pernicious possible problem. If you erase and retype the line, you eliminate the possibility of them pretty easily :)
Chirael
Try perl -c myscript.pl from the command line and if that works, try just perl myscript.pl, and let us know what happens for both.
Chirael
In addition to `ls /usr/bin/perl`, it might help to find the first Perl interpreter in his PATH with `which perl`
Telemachus
it's starting with #!/usr/bin/perl
Nii
If you retype the line, retype it as #!/usr/bin/env perl instead of /usr/bin/perl.
William Pursell
+2  A: 

As Chirael said, it sounds like your shebang line (the directive at the top of the file, that tells the shell how to run the script) is invalid somehow. You can bypass the shebang line entirely by invoking your script as:

perl myscript.pl > myfile.txt

You also don't need to set the script's executable bit, as with this method of invocation, you are only reading the script, not executing it (from the shell's perspective).

Ether
This is a work around, but I think Manni's comment on my answer is the correct solution. In that the entire command was called in quotes.
EmFi
A: 

According to this thread, it could be from different representation of the new line.

Have you written the script on a windows box and copied over to your linux box?

What is your text editor?

ccheneson