Your system sets up your system environment using a set of specifications defined in the initialization files. If you want to temporarily modify your environment for the current work session you can issue commands directly at the command prompt. However, if you want to modify your working environment on a more permanent basis, you can store "permanent" environment variables in the .profile, .login, or .cshrc files.
To display the environment variables currently set on your system:
Type the env command and press Return:
You can also use the env command to identify your
login shell. It is specified in the SHELL
environment variable. In the example above, the shell is set
to /bin/sh (the Bourne shell).
This section describes some of the more commonly used environment variables. Many of these variables may already be in your user profile. As previously mentioned, your user profile file (.profile for the Bourne and Korn shells and .cshrc for the C shell) is located in your home directory.
Hidden ("dot") files can be listed by typing ls -la.
The following is a partial list of environment variables that can be included in your user profile. The syntax for defining environment variables depends on the shell you're using:
CDPATH
-
Specifies the directories to be searched when a unique directory name is typed
without a full path name.
HISTORY
-
Sets the number of commands available to the history command
(for the C shell only).
HOME
-
Defines the absolute path to your home directory. The system uses this information
to determine the directory to change to when you type the cd
command with no arguments.
LANG
-
Specifies the local language. Appropriate values are: Japanese, German, French,
Swedish, and Italian.
LOGNAME
-
Defines your login name. The default for this variable is automatically set
to the login name specified in the passwd database as
part of the login process. See System Administration Guide, Volume 1 for
information on the passwd database.
MAIL
-
Specifies the path to your mailbox. usually located in the /var/mail/username directory, where username is your login name. See Chapter 7, Using Mailfor
more information on this file.
MANSECTS
-
Sets the available sections of on-line man pages.
PATH
-
Lists, in order, the directories that the system searches to find a program
to run when you type a command. If the appropriate directory is not in the
search path, you have to enter it or else type the complete path name when
you enter a command.
The default for this variable is automatically defined and set as specified in your .profile file (Bourne or Korn shell), or .cshrc file (C shell) as part of the login process.
PS1
-
Defines your command prompt. The default prompt for the Bourne and Korn shells
is the dollar sign ($). The default prompt
for the C shell is the percent sign (%).
The default prompt for root in either shell is the pound sign (#).
TERMINFO
-
Specifies the path name for an unsupported terminal that has been added to
the terminfo database. You do not need to set this variable
for default terminals in this database. See System Administration Guide, Volume II
for information on the terminfo database.
TERM
-
Defines the terminal you're currently using. When you run an editor, the system
searches for a file with the same name as the definition of this variable.
It first searches the path (if any) referenced by the TERMINFO
variable, and then the default directory, /usr/share/lib/terminfo, to determine the characteristics of the
terminal. If a definition is not found in either location, the terminal is
identified as "dumb."
PATH
VariableThe PATH
environment variable
is used to locate commands within the SunOS directory hierarchy. By setting
the PATH
you create a fixed set
of directories that the system always searches whenever you enter the name
of a command.
For example, if you have no PATH
variable set and you want to copy a file, you need to enter the full pathname
for the command, /usr/bin/cp. However, if you have set
the PATH
variable to include the
directory /usr/bin, then you can simply type cp and your system will always execute the command. This is because
your system searches for the cp command in every directory
named in the PATH variable, and executes it when it is found. Using the PATH
variable to list the commonly used SunOS
command directories can thus significantly streamline your work.
For the Bourne and Korn shells, the PATH
variable is specified in your .profile
file (in your home directory) using the following syntax:
PATH=.:/usr/bin:/home/bin |
where home represents the path name of your home directory.
For the C shell, the PATH
variable is specified in your .cshrc file (in your home
directory) using the following syntax:
set path=(. /usr/bin home/bin) |
where home is the path name of your home directory.
In the C shell you can use the shortcut ~ to represent the path name of your home directory.
If you modify the PATH
variable,
and you are running the C shell, use the source command
to make the changes effective in your current window without having to logout:
example% source .cshrc |
If you are running the Bourne or Korn shell, type the following to make the changes effective in your current window without having to logout:
$ . .profile |
Aliases are useful shortcuts for commands you often type. For example, the default setting for the remove command (rm) does not ask for confirmation before removing files. Sometimes this is inconvenient, as a typing error can remove the wrong file. However, the C shell lets you use the alias variable to change this by adding the following line to your .cshrc file:
alias rm 'rm -i' |
With this line in the .cshrc, typing rm will now be the same as typing rm -i, which is the interactive form of the rm command. You will then always be asked to confirm the command before any files are deleted. (The quote marks around rm -i in the example above are necessary to include the blank space between rm and -i. Without them the C shell cannot correctly interpret the text after the space.
To make your changes to the .cshrc file effective immediately in your current window, use the source command. The source command causes the system to read the current .cshrc file and execute the commands in it:
example% source .cshrc |
The syntax you use to change your command prompt depends on whether you are using the Bourne, Korn or C shell.
For the Bourne or Korn shells, you redefine your command prompt with the PS1 command. The following are three examples:
PS1=": " PS1="`hostname`: " PS1="`hostname`{`id`}}: " |
The first example sets the prompt to a colon (:), followed by a space.
The second example creates a prompt consisting of your machine name followed by a colon and a space.
The third example sets the prompt to your machine name, followed by your login name in braces {}, a colon, and a space.
Type any of the examples above to change your current command prompt. The prompt will remain until you change it again, or logout.
If you want to make your changes more permanent, add one of the above examples (or a prompt of your own creation) to your .profile file. If you do this, the prompt you specify will appear each time you login in or start a new shell.
For the C shell, you personalize your command prompt with the set prompt command. The following are three examples:
set prompt="% " set prompt="`hostname`\!: " set prompt="`hostname`{`id`}}: " |
The first example sets the prompt to the percent sign, followed by a space.
The second example creates a prompt consisting of your machine name followed by the history number of the command (hostname1, hostname2, hostname3, and so on).
The third example sets the prompt to your machine name, followed by your login name in braces, a colon, and a space.
Type any of the examples above to change your current command prompt. The prompt will remain until you change it again, or logout.
If you want to make your changes more permanent, add one of the above examples (or a prompt of your own creation) to your .cshrc file. If you do this, the prompt you specify will appear each time you login in or start a new shell.
There are many other variables which you can set in your .profile or.cshrc files. For a complete list, refer to the man Pages(1): User Commands. The following are a few brief descriptions of some of the more commonly used options.
Use set noclobber to prevent unintentional overwriting of files when you use the cp command to copy a file. This variable affects the C shell only. Enter the following in your .cshrc file:
set noclobber |
Use set history to set the number of commands saved in your history list. The history command is useful to view commands you have previously entered. The history file can also be used to repeat earlier commands. This variable affects the C shell only. Enter the following in your .cshrc file:
set history=100 |
You can also affect the Bourne and Korn shells in the same manner by placing the following in your .profile file:
HISTORY=100 |