Sorry for the long delay, but I have been busy with getting ready for school again and moving into my new apartment.
This is in some ways a continuation of my post Changing Modes. As pointed out in one of the comments (thanks to Miorel) some people might wonder why you would have to type
./hello_world instead of just
hello_world in order to execute the Perl script. Well I though about this for a second and thought, “Well to run a script that isn’t one implemented by the OS you must place
./ before it. This tells the OS that you are trying to execute a file.” For example, if you want to run Firefox you just need to type
firefox and not
./firefox. If you are curious-and you should be-and enter
./firefox into the terminal you should get the following message, “
bash: ./firefox: No such file or directory” (unless you for some reason have a file or directory called ./firefox, but why would you?).
Though that might answer might be good enough for some, I wanted to know why this was so, and if it was possible to change it so that you would only need to type
hello_world (and not
./hello_world). This is where $PATH comes into play. I am going to try my best to explain this, and will also provide links to other sites for further reference.
To begin with here is a one line definition-which sadly isn’t mine, but gets the point across-of what the PATH variable is.
PATH is a list of directories where commands are looked for.
So when I type
echo $PATH into the terminal I get the following:
Returning to our original example; if you were to type
hello_world into the terminal. The OS would first look for a command (a file with the x bit set) with that name in /usr/local/sbin. If one is found it is run, if not it continues onto /usr/local/bin, and so on.
Now if we would like to only have to type
hello_world, all we would have to do is add its directory to the PATH variable. Suppose that our script is in the directory /Mine. First I will show you the WRONG WAY to do this. Then two different correct ways (though I am not all that sure about which is better to use as of yet).
THIS IS THE WRONG WAY!!!
This is wrong because it will replace the original PATH variable with /Mine, and I am sure that you don’t want this.
Correct way #1:
Correct way #2:
As you can see, the first one will add /Mine to the beginning, and the seoncdd to the end of the PATH.
Here are two sites you can visit if you wish to learn more about the PATH variable. http://www.faqs.org/docs/Linux-mini/Path.html and http://www.troubleshooters.com/linux/prepostpath.htm