Envirionment and Path:

Part 1: making an executable shell script

Create a local variable hey (the greater_than symbol represents your shell prompt):
> hey=hello
> echo $hey
hello
Now make your first shell script:
Put the line echo $hey into a file. Save the file as hey_there, and change the permissions on hey_there to make it executable:
> chmod 755 hey_there 
Now run this file:
>./hey_there

>
What happened?
The variable $hey is a local variable to the shell process. When it spawned the process hey_there the variable $hey was not passed down to this process. So there is no value for $hey in the subprocess. Try env you will see that hey does not show up.
Now make a $hey a global variable:
> export hey=hello
and run the command:
>./hey_there
hello
>
Check the environment env. Do you see the variable show up?

Part 2: making your own bin directory

The first part is not so hard
From your home directory make the directory:
> mkdir bin
Now the tricky part add the directory to your PATH:
> export PATH="/home/you/bin:$PATH"
What's going on?
You are exporting the variable PATH (remember the first part of the homework?) to equal your new directory plus the old value of the variable $PATH. Remember the $PATH is expanded by the shell *before* the arguements are passed to export so this works.
Don't get confused
When declaring the shell variable you don't use the $. but when you want to use the value of a shell variable you do.
Making the change in PATH permanent
The astute reader has noticed that the change in PATH just decsribed will only last for this session with the shell. Inorder to make this change permanent, the line export PATH="/home/you/bin:$PATH" should be called for each shell upon log-in. Unfortuantely there is some difference about how the distributions handle this. Unsually these files are in your home directory and called either .bashrc, or .bash_profile. .profile is sometimes a file which is called by any shell which is not good for this command becasue export is a bash built-in command (try which export). On my Redhat system .bash_profile calls .bashrc which calls /etc/bashrc (for system wide configuration stuff). Poke you nose in these files (less,cat?) and try to figure out which one is used in your distribution. There may be information pertaining to this in your distribution manuals. If there aren't any files. I would add the line to a file called .bashrc and log in again to see if the PATH was changed.
Now that you know how to make your own directory for executables, you just have to learn how to make more and more interesting ones right?

Copyright Marco Scoffier, released under the GFDL