<<

. 19
( 69 .)



>>

after the ll command just as you can with the original ls
permanent by saving them in your .tcshrc file. See "Edit
-l command.
Your .tcshrc File" in this chapter.
You can also redefine existing commands to be aliases. For
example, if you are afraid that you may mistakenly delete an
important file because you do not always remember to use
the -i option with the rm command, you can set an alias as
follows:

alias rm 'rm -i'

SET COMMAND ALIASES




– The shell executes the long
‹ Type a long command in › Type the short alias with
SET COMMAND ALIASES
single quotes and press any appropriate arguments command.
„ Type alias and a space. Return. and press Return.
¤ Type a short alias.

82
6
CUSTOMIZE YOUR SHELL




Most advanced Unix users like to avoid typing
unnecessary characters, and thus make extensive use of
the alias command. Some of the most common and
useful aliases appear in the following table. You can save
these aliases by storing them in your .tcshrc file.

SHORT ALIAS LONG COMMAND DESCRIPTION
cd pushd Always maintain the directory stack.
cd.. cd .. In case you forget the space.
cp cp -i Prevent cp from overwriting files.
home cd ˜ Return to Home directory.
ll ls -l Long file listing.
ls ls -F Always include file-type indicator.
print lpr It is easier to remember print than lpr.
rm rm -i Prompt for each file deletion.
.. cd .. Change directory to the parent directory.




¤ Type alias, a space, then ¤ Type the name of an alias
LIST ALL CURRENT ALIASES DELETE AN ALIAS
an alias, and press Return. and press Return.
„ Type alias and press „ Type unalias and a space.
– The shell lists the long – The alias is no longer
Return.
command for that alias. defined.
– The shell lists all aliases.
83
UNIX FOR MAC



SET SHELL VARIABLES
The first example sets the variable without giving it a value;

Y
ou can affect the way your shell functions by setting
it simply sets the switch to on. The second example sets the
shell variables. A shell variable can either have a value
variable to a value, like filling in the blank on a job
or it can have no value ” in which case the value is
application.
null. You can think of shell variables without values as
simple on-or-off switches. If the variable is set, the shell
If you type set by itself on a line, you see the list of your
functions as if the switch is on. If the variable is not set, the
current shell variables. The shell automatically sets many of
switch is off.
these either when you start up the Terminal window or
when you type commands. In addition to these automatic
A shell variable with a value, on the other hand, acts like a
variables, you can set a number of other variables that
blank line on an application that you can fill with the
affect how your shell works. These appear in the table on
correct information. If you are applying for a job, for
the facing page.
example, there is a line labeled Name on the application
where you fill in your name, and another labeled E-mail
Shell variables normally last as long as the Terminal window
where you write your e-mail address.
is open, although you can use the unset command to get
rid of shell variables beforehand. To make your shell
To set a variable, you use the set command:
settings permanent, see "Edit Your .tcshrc File" in this
chapter.
set variable
set variable = 'value'



SET SHELL VARIABLES




– This is an example of a ¤ Type a variable name and
LIST CURRENT SET A SHELL VARIABLE
SHELL VARIABLES Shell variable with no value. press Return.
„ Type set and a space.
„ Type set and press Return. – This is an example of a – The shell variable is set but
– The shell displays all shell Shell variable with a value. has no value.
variables.

84
6
CUSTOMIZE YOUR SHELL


You can set any variables you want, as long as their names start
with a letter and contain only letters, numbers, and the underline
symbol. However, these variables only affect the shell if their name
corresponds to the list of special variables understood by the shell.
Some of the most useful special variables appear in the table below.

VARIABLE SAMPLE VALUE MEANING
No value Correct command mistypings.
autocorrect
Exit the shell after 30 minutes of no activity.
autologout 30
Use improved, case-insensitive, tab completion.
complete enhance
No value Remove duplications in the pushd directory stack.
dunique
Show last 75 command lines.
history 75
No value Shell commands do not beep at you.
nobeep
No value Redirection does not overwrite existing files.
noclobber
Your path.
path (/bin /usr/bin)
No value Flash the Terminal window instead of beeping.
visiblebell
There are a number of variables that are automatically set by the shell
such as version, uid, user, shlevel, term, and home. You should
not change shell variables unless you know what effect they produce.




‹ Type a variable value in ¤ Type a name of a variable
SET THE VALUE OF A SHELL UNSET A SHELL VARIABLE
quotes, and press Return. and press Return.
„ Type set and a space. „ Type unset and a space.
– The shell variable is set to – The shell variable is unset.
¤ Type a variable name the value.
followed by an equal sign (=).


85
UNIX FOR MAC




SET ENVIRONMENT VARIABLES
the variable. Note that unlike the set command, the

Y
ou can change values that applications inherit by
setenv command requires no equal sign. You should type
setting environment variables. Environment variables
environment variable names in all capital letters to
are similar to shell variables. Any command that the
distinguish them from shell variables.
shell runs can access environmental variable settings; the
environment variables represent the environment in which
You can get a listing of the current environment variables
you run commands. Depending on the command, the shell
and their values by typing the printenv command. If you
may or may not use an environment variable to affect the
compare this listing to that of shell variables ” viewed by
execution of the command.
typing set ” you can see that there is some duplication.
Pairs of variables such as HOME/home, TERM/term, and
For example, if you type a V in less, the less command
SHLVL/shlvl have the same names and values. This
uses the EDITOR environment variable, so that you can edit
duplication allows the values to be accessed by the shell as
the file that displays. To set an environment variable, you
well as by commands run within the environment of the
use the setenv command:
shell. These variable pairs automatically link so that
changing one changes the other.
setenv VARIABLE
If you need to unset an environment variable, you can use
setenv VARIABLE 'value'
the unsetenv command. Your environment variables last
The first example sets the variable without a value, that is, only as long as the current Terminal window is open, unless
with a null value, and the second example gives a value to you save the setenv commands in your .tcsrhc file.

SET ENVIRONMENT VARIABLES




– The shell displays all ¤ Type an environment
LIST CURRENT ENVIRONMENT SET AN ENVIRONMENT
VARIABLES VARIABLE
current environment variable name and press
„ Type printenv and press „ Type setenv and a space.
variables. Return.
Return. – The shell sets the
environment variable, but
with no value.
86
6
CUSTOMIZE YOUR SHELL


Applications are the primary users of environment variables. This means that each
application may have a different set of environment variables that it looks for in
order to affect its operation. To know which environment variables to set, you must
consult the documentation for the programs you use. You can usually find this
information on the manual page by using the man command.
Some environment variables are standard and are understood by many programs.
Some of these are listed in the table below. Those marked with a plus symbol (+)
are set by the system and should generally be left unchanged.

VARIABLE SAMPLE VALUE MEANING
Your preferred text editor.
EDITOR /bin/vi
HOME (+) Your Home directory.
/Users/kynn
LANG (+) Your preferred language.
en_US
Your path.
PATH /bin:/usr/bin
PWD (+) /Users/kynn/Music The current directory.
SHELL (+) The pathname of your shell.
/bin/tcsh
TERM (+) The Terminal application emulates a vt100.
vt100
USER (+) Your short username.
kynn
Your preferred text editor.
VISUAL /bin/vi




‹ Type a value in single ¤ Type the name of an
SET THE VALUE OF AN UNSET AN ENVIRONMENT
ENVIRONMENT VARIABLE VARIABLE
quotes and press Return. environment variable and
„ Type setenv and a space. „ Type unsetenv and a press Return.
– The shell sets the
space. – The environment variable
¤ Type the name of an environment variable
to the value. is unset.
environment variable and a
space.
87
UNIX FOR MAC


SET YOUR PATH
This command immediately updates your path as well as

<<

. 19
( 69 .)



>>