Editing the scripts you already have
Before we get to writing new scripts, I want to
point out that you have some scripts of your own
already. These scripts were put into your home
directory when your account was created and are
used to configure the behavior of your sessions on
the computer. You can edit these scripts to change
In this lesson, we will look at a couple of
these scripts and learn a few important new
concepts about the shell.
Up to now, we really have not discussed exactly
what commands are. Commands can be several
different things. Some commands are built into the
shell itself. That is, the shell automatically
understands a few commands on its own. The commands
cd and pwd are in this group. Commands
implemented in the shell itself are called shell
builtins. To see a list of the commands built
into bash, use the help
The second type of commands are the executable
programs. Most commands are in this group.
Executable programs are all the files in the
directories included in your path.
The last two groups of commands are contained in
your runtime environment. During your session, the
system is holding a number of facts about the world
in its memory. This information is called the
environment. The environment contains such
things as your path, your user name, the name of
the file where your mail is delivered and much
more. You can see a complete list of what is in
your environment with the set
The two types of commands contained in the
environment are aliases and shell
Now, before you become too confused about what I
just said, let's make an alias. Make sure you are
in your home directory. Now, using your favorite
text editor, open the file .bash_profile and add
this line to the end of the file:
alias l='ls -l'
The .bash_profile file is a shell script that is
executed each time you log in. By adding the alias command to the file, we
have created a new command called "l" which will
perform "ls -l". To try out your new command, log
out and log back in. Using this technique, you can
create any number of custom commands for yourself.
Here is another one for you to try:
alias today='date +"%A, %B %-d, %Y"'
This alias creates a new command called "today"
that will display today's date with nice
By the way, the alias
command is just another shell builtin. You can
create your aliases directly at the command prompt,
however they will only remain in effect during your
current shell session. For example: