In part one, we created a file called .bash_profile in our home directory that contained a set of aliases for the
mv commands. This file is actually a shell script file: it contains three commands that run in sequence when the .bash_profile file is read. This file turns out to be exactly where we want to set our new
PATH environment variable! Open a new Terminal window and type in
ls -a to show a listing of all files, including the hidden files indicated by the period in front of their names, and you'll see your .bash_profile file:
Figure 3. .bash_profile
You'll open .bash_profile using
nano and add the path to the scripts folder in the system environment using the
export command (if you didn't follow along in part one and create this file, you'll do so now):
Figure 4. Add
Remember that to write to this file and save it, you will need to use the keystrokes
^O (WriteOut) and then
^X (Exit). Back at the Terminal, activate the changes by typing:
If you run the
echo $PATH command again, you'll see this:
Figure 5. New
Now, we're ready! Let's get started!
First Shell Script
Let's create a shell script to see who the users are on my machine:
1. Open a new Terminal window.
cd to your new scripts directory:
cd to scripts
3. Create a new shell script by calling
nano and naming your new script firstscript.sh.
4. When you hit the
nano will open a new file called firstscript.sh.
Figure 8. firstscript.sh
5. Type in the following:
Figure 9. Contents of firstscript.sh
6. Then save the file (
^O) and exit (
^X). Take a look in your scripts folder and you'll see your newly created first shell script!
Figure 10. First shell script