A UNIX system can have hundreds or thousands of directories - and a lot
Even if you remember all the pathnames, typing them over and over can be a pain.
Your account probably already has some helpful
shell and environment variables (6.8
You can add more from the command line or from your
shell setup files (2.2
To see what environment variables are set, use the env
(System V) or
The command set
should show shell variables (some of these might
be repeated in the environment).
Here's part of what happens on my account:
mail (60 /usr/mail/jpeek)
UNIX programs use a lot of those environment variables.
For instance, my email system finds its setup file from MH
But I can use environment variables for other things, too.
For instance, when I want to edit my email setup file, I can type
from any directory.
The shell expands
Check your environment and see what you've got; the names usually
explain the variables pretty well.
The shell uses shell variables like
I can check incoming messages with the command
tells the C shell to pick the second word from the list in
I've set other shell variables for myself.
When I send some mail messages, I want to watch the system mail log to
see the message being delivered.
I just type:
tail -f $maillog
09/08/96 17:13:27: [m0kJN4x-0000AKC] new msg: from firstname.lastname@example.org
09/08/96 17:13:28: [m0kJN4x-0000AKC] <jim> ... delivered
09/08/96 17:13:42: [m0kJN4x-0000AKC] <email@example.com> ... delivered
Are there files or directories that you refer to a lot - ones that aren't
right for the
or a shell alias?
Pick a likely shell variable name and add the variable to your
You can store more than one pathname in the same variable - either by
separating them with spaces or by using wildcards:
# C shell variables:
set worklog=~/todays_worklog Single file, defined when set
set projfiles=(/work/beta/data_3.9*) Many files, defined when set
set currdata='/work/beta/data_5*' Many files, defined when used
# Bourne shell variables:
worklog=$HOME/todays_worklog Single file, defined when set
projfiles="`echo /work/beta/data_3.9_*`" Many files, defined when set
currdata='/work/beta/data_5*' Many files, defined when used
You could type
vi + $worklog
any time you want to add a note to the end
of the file todays_worklog
in your home directory.
to start at the end of the file.)
The shell expands the asterisk (
) when it sets the projfiles
variable and stores a list of the files as they were when the
variable was set
(If the list of files changes, it'll be reset when you start your next shell.)
You could print all those files any time you wanted to by typing a
The C shell also lets you
pick individual files (47.5
from the list - for
would print the ninth file from the list.
When the currdata
variable is set, the single quotes (
prevent expansion (8.14
of the wildcard (
Instead, the pathname
is expanded when you use
the variable - like
- to show
you the files as they
are at the time you use the variable.
You can also use variables to store the paths to directories.
, or any other command with the variables.