Our Unix & Perl Primer is written in a way that explicitly assumes that you are using a USB drive (called 'USB' no less). It is possible, and in many ways desirable, to work through the Primer with the files from the course material in your home directory instead of the USB drive. However, you will need to make a few changes.
Let's assume that you copy the 'Unix_and_Perl_course' directory to your home directory. If your user name was 'keith' and you were using a non-networked Mac, then your home directory can be accessed at:
/Users/keith
This will be different on other Unix/Linux systems, but the actual location of your home directory doesn't really matter as you can always find it by running any of the following and then running pwd:
cd ~keith
cd ~
cd
cd $HOME
Even this is not really necessary as opening a new terminal places you in your home directory by default.
Now we need to amend the .profile file. When teaching from the USB drive, we need to trick the operating system into thinking that /Volumes/USB/Unix_and_Perl_course is the home directory, and then we make it change directory to that location. This is done by using the source command on the .profile file which is in /Volumes/USB/Unix_and_Perl_course.
No need to do any of this when using our actual home directory. Simply first move the .profile file to be in your actual home directory and then comment out (by adding a # sign to the start of the line) or remove the following lines from the .profile file:
HOME="/Users/Behr/Unix_and_Perl_course"
cd $HOME
If there is a .profile file in your home directory, it will be read automatically every time you open a new terminal window. This only happens if the file is in your home directory (no other directory will do this). If you are running Ubuntu Linux, this is a little more complicated. Technically speaking, the .profile file is only read automatically if the Terminal program is running something called a 'login shell'. This is the default on many, but not all, Unix systems. On Ubuntu, you have to open your Terminal's preferences and then find the checkbox which says 'run as a login shell' (or similar text, I'm writing this from memory). This is hidden in one of the preference tabs.
Now we need to make two other changes to the .profile file. These concern specifying the environment variables $PATH and $PERL5LIB. If you have the Unix_and_Perl_course directory in your home directory, then these lines should look something like this:
export PATH=$PATH:~/Unix_and_Perl_course/Code
export PERL5LIB=$PERL5LIB:~/Unix_and_Perl_course/Code
If you are — like too many people in this world — keeping the Unix_and_Perl_course directory on your desktop (along with everything else you download), you'll need to change the above lines. You can also use $HOME as a substitute for ~.
You will know if all this is working by:
- Opening a new terminal window
- Typing echo $PATH (should now have an extra directory at the end)
- Typing echo $PERL5LIB (as above)
- checking that the other commands in .profile are working (e.g. aliasing rm to rm -f)
Hope this helps people.
Keith