How do I fix "bash: perl myscript.pl: command not found"?
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 edit开发者_开发问答ing 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
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.
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.
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";'
?
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).
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?
I had the same issue, and traced it to DOS line endings (^M). Running dos2unix on the .pl file fixed the issue.
Please use, ./myperl.pl > outfile.txt to give the current directory path thanks
精彩评论