| ACADEMIC COMPUTING and COMMUNICATIONS CENTER | |||||||||
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.
|
||||||
| 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:
The basic form of an alias is:
with no space before or after the equal sign. For example:
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:
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:
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: and then you export the variable: export variableFor instance: PS1='\$PWD)--> ' 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 |
||||||
| 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.
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:
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:
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 |
|