ACCC Home Page ACADEMIC COMPUTING and COMMUNICATIONS CENTER
Accounts / Passwords Email Labs / Classrooms Telecom Network Security Software Computing and Network Services Education / Teaching Getting Help
 
Unix 101
0. Contents 1. Getting Started 2. Basic UNIX 3. Email 4. vi Editor 5. Printing 6. Printing FAQ
7a.Connecting to Unix, Win 7b.Connecting to Unix, Mac 8. Customizing Unix 9. Accts & Password FAQ 10. Using UNIX FAQ 11. Related Links  

Customizing UNIX: environment variables, aliases, and the .profile and .env files

  The Profile file in your home directory is a collection of Korn shell commands that are executed whenever you login. Commonly, the Profile file is used to set environment variables and shell options. You can also put command aliases in your Profile file, but it's better to put them in a separate file -- commonly called .env (which is pronounced: dot-e-n-v)-- that you define and execute in your Profile (which is pronounced: dot-profile).

This document briefly introduces environment variables, shell options, and aliases, and gives sample Profile and .env files.

The commands in this document assume that you're using Korn shell, which is the default login shell on all the ACCC UNIX machines. Shell variables (like $PRINTER and $ENV, which are introduced below) are defined slightly differently in C shell. For example, to select the U-Print system as your default printer in csh you'd use the printer named uprint:

PRINTER uprint
setenv PRINTER

 
   
 
     
Aliases
 

Aliases are used to rename commands, and sometimes to include options. You can put aliases in your Profile file, but if you do, they will not be "exported" to subshells. So it's better to put them in a separate file in your home directory, commonly called .env, and execute the .env file from your Profile:

ENV=~/.env
export ENV
. $ENV

The basic form of an alias is:

alias mycommand=UNIXcommand

with no space before or after the equal sign. For example:

alias search=grep

allows you to use the more mnemonic name search for the existing UNIX command grep. A useful alias that includes an option is:

alias  rm="rm  -i"

which executes rm -i files each time you enter rm files thereby saving you from accidentally deleting your files or directories. Another alias:

alias print="lpr  -P"

might make it easier for you to remember how to print files on UNIX.

 
     
Options
 

Options change the shell's behavior by turning controls on or off as in:

to turn options off: set +o options
to turn options on: set -o options

Note that the plus and minus are the opposite of the usual: plus for on and minus for off. options can be one option name or a list of option names separated by blanks. For example:

set -o vi

turns on editing of the command line in the shell.

 
     
Variables
 

Variables change the shell's behavior, or that of other programs, by providing a value (instead of an on/off condition) in the form:

variable=value

and then you export the variable:
export variable
For instance:
PS1='\$PWD)--> '
export PS1

sets the first prompt string (PS1) to tell you the current directory and changes the prompt from $ to: the name of the current directory ($PWD) followed by -->

Another useful variable is PRINTER, which selects a default print destination.

PRINTER=grc105
export PRINTER
 
     
Using .profile and .env files
  Now that you have some suggestions of what to put in your Profile and .env files, here's how to use them.
  1. Create a file in your home directory named .env (actually, any other name would do, but since the variable you set to execute this file in Korn shell is $ENV, .env seems like a good choice), and put in it the aliases that you want to set.

    Putting together the examples given above, you'd have a ~/.env file as follows:

    alias  search=grep
    alias  rm="rm -i"
    alias  print="lpr -P"


  2. Put the options and environment variables into a file in your home directory named Profile, and be sure to include the commands to define, export and execute .env.

  3. set -o vi
    PS1='\$PWD)--> '
    export PS1

    PRINTER=uprint
    export PRINTER

    ENV=~/.env
    export ENV
    .  $ENV

In the Korn shell, your Profile is executed each time you login. When you make a change in it like this, you might want to execute it yourself, to make the changes for your current login session. So to set the alias for your current login, enter:

. Profile

Note the "period space" at the beginning of this command, and in the last of the three lines you added to your Profile file in Step 2. Yes, it is necessary. The "dot command" tells the shell to run the command as if you has entered the commands yourself at the command prompt. Without it, the command is run in a subshell, and the changes will disappear when the subshell closes.

Want to check whether the alias "took"? In Korn shell, the command:

whence cmdname

returns the pathname when cmdname is the name of a script or executable program, or the command executed when it's an alias.

 
 

Unix 101 Previous: 7b.Connecting to Unix, Mac Next: 9. Accts & Password FAQ


2005-8-18  ACCC documentation
UIC Home Page Search UIC Pages Contact UIC