On Mar 7, 2008, at 7:35 PM, Gary Yang wrote:
Below is my Perl script. The script named, test1.pl
I have to type, "perl test1.pl" in order to run it. I got command
not found if I simply typed test1.pl. Can someone tell me why and
how to fix it?
Indeed, as Chas. mentioned, the script you have written must be
'executable'. There is a distinction between a script that is plain
text, like yours, and a script that can 'execute' that plain text as
if it were instructions to the computer. When you called your script,
you did it like this: test1.pl But your computer did not understand
that you wanted to execute all the commands in your script, it just
saw plain text.
To tell your computer to execute your script, you have to change the
permissions. That is, you have to give permission to execute the
script. The way to do that is to use a command called 'chmod'. chmod
'CHanges file MODes' - it turns a plain script into an executable
script. Do a `man chmod` to find out more, or just do what Chas.
chmod a+x test.pl
Now you can call your script and your computer will understand, "Aha!"
it will say. "I am to execute each command in this file as if someone
wrote it on the command line!" To call your script, do this:
See the dot and the slash before your script's name? That says,
'execute this script right here.' Now you should see the output from