![]() |
Customize Your Unix Environment | |
---|---|---|
© December 22, 1992 | B-14 |
This how-to describes several ways to customize your Unix environment, including how to prevent accidental overwriting of files and how to set up aliases for Unix commands. It also describes how options are customized using shell and environment variables.
Unix is a layered operating system.
![]() | The shell acts as an interpreter between you and the Unix kernel. The kernel in turn directs the hardware to handle the basic operations required by the tasks you initiate, for example reading and writing data in disk files. In general, you never deal directly with the kernel, but only with the shell. |
The shell is a program which relays your commands to the kernel and returns its responses to you. There are two common Unix shells in use, the C shell (pronounced "sea shell") and the Bourne shell (named after its developer).
Whenever you login to a Unix host, a shell is invoked. The prompt for the C shell is %; the prompt for the Bourne shell is $. In general, the C shell is better for interactive command interpretation, while the Bourne shell has features which are useful for people doing shell programming.
ACS has configured your Unix account to invoke the C shell when you login. You may invoke additional shells concurrently or sequentially in the course of a Unix session.
Each time you login to a Unix host, the system looks in your home directory for initialization files. Information in these files is used to set up your working environment. The C shell uses two files called .login and .cshrc (note that both file names begin with a period).
These files can contain any Unix commands. It is usual practice to put instructions to set up terminal conditions in .login and to put functions specific to the C shell in .cshrc (which stands for C shell run commands). .login is read and processed after .cshrc is.
You will find files named .login and .cshrc in the home directory of your Unix account; these were set up by ACS when your account was created. They invoke additional files under the user ID proto (for prototypical user) which contain commands useful to all users of the ACS Unix hosts.
.login and .cshrc also contain commands to invoke files in your home directory called.mylogin and .mycshrc, if the latter exist. .mylogin and .mycshrc are your personal initialization files. You should use .mylogin and .mycshrc (not .login and .cshrc) to customize your Unix environment.
Use a Unix editor such as vi, emacs or pico to create .mylogin and .mycshrc and add commands to them.
If you have previously created .mylogin and/or .mycshrc, you should make a backup copy of them before modifying them. To create, for example, a backup of .mylogin, type
cp .mylogin .mylogin.old
When you modify one of your initialization files,
the change is not activated until the system reads that file again.
Normally, this occurs when you next login.
You can make the change take place immediately by giving
the command:
source .mycshrc
If you modify your .mylogin file, the command is
source .mylogin
This forces the system to re-read the file and execute the commands it contains.
With Unix, you may redirect the output of a command to a file using the redirection symbol ">" (see how-to B-7, Examine Unix Files and Redirect Output, for more on redirecting).
But this redirection mechanism occasionally causes problems if you accidentally redirect output to an existing file. When you redirect output to a file that already exists, any previous contents are deleted before the command is completed. In effect, the new material overwrites what was originally in the file.
You can prevent this overwriting by adding the following line to your .mycshrc file:
set noclobber
Now if you redirect output to an existing file, you will see a message informing you that the file exists, and the overwriting will not occur.
To turn off this safety feature for the current session, type
unset noclobber
at the Unix prompt. Note that set noclobber doesn't prevent you from accidently overwriting an existing file when you use the cp command to copy one file into another. To prevent overwriting when using cp, see the section below Creating aliases for Unix commands.
The history mechanism keeps a record of commands you have previously entered (history is described in how-to B-12, Record, Reissue and Rename Unix Commands). You specify the number of commands to be remembered.
ACS Unix accounts are preconfigured with history set to 100 (i.e., the C shell will remember the last 100 commands you typed). To change this number, for example to increase it to 200, add the following line to your .mycshrc file:
set history=200
The alias command lets you give alternate names to Unix commands or to specify particular options to use with commands. Aliases are described in how-to B-12, Record, Reissue and Rename Unix Commands.
You can include aliases in your .mycshrc file so they are available each time you login. For example, to permanently set an alias for the command rm so that it includes the -i option (asking for confirmation for files to be removed), put the following line in your .myschrc file:
alias rm rm -i
To prevent accidental overwriting when using the cp and mv commands, add the commands
alias cp cp -i
alias mv mv -i
ACS Unix accounts are preconfigured with some aliases, including
alias ls ls -aC
alias help man
How-to B-15, Use Job Control with the Unix C-shell, describes how to run jobs in the background. Since these background jobs are executed behind the scenes, you may not readily know their current status. Setting notify informs the shell that you want to be alerted immediately of any changes in status of background jobs. Put the following line in your .mycshrc file:
set notify
To turn off this background notifying feature for the current session, type
unset notify
at the Unix prompt.
If you don't want other Unix users to try to contact you using the write or talk commands, add the following line to your file .mycshrc:
mesg n
(write and talk are described in how-to B-9, Find out about others using Unix and "talk" to them.)
noclobber, history and notify are examples of C shell variables. As shown above, the set command sets values for these variables.
Unix utilities, editors and application programs often have environment variables to set options and parameters. Environment variables are described in the program's or utility's man page entry. (For information on man, see how-to B-10, Use Unix Online Documentation.)
Use the setenv command to set an environment variable for a Unix program. For example, to customize the mpage "multiple-up" printing utility so that by default it will print 4 reduced landscape pages per side of paper, add this line to your .mycshrc file:
setenv MPAGE -4l
To see the current value of a shell or environment variable, for example, the C shell variable history, type
echo $history
To see the current values of your C shell variables, type set by itself. To see the current values of your environment variables, type env.