Bash and Korn Shell Environment Variables
The bash and ksh93 shells store special variable information that is known
to the shell as an environment variable. To view a complete list of the current
environment variables for the bash shell, use the declare command.
$ declare
BASH=/usr/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINEND=()
BASH_SOuRCE=()
BASH_VERSINFO=([0]=''3'' [1]=''2'' [2]=''25'' [3]=''1''
[4]=''release'' [5]''
.
.
.
For the ksh93 shell, use the set command, which is the
bash shell's declare command equivalent.
$ set
COLUMNS=80
ENV='$HOME/.kshrc'
FCEDIT=/bin/ed
HISTCMD=3
HZ=''
IFS=$' \t\n'
KSH_VERSION=.sh.version
LANG=C
LINENO=1
.
.
.
To print environment variables for either shell, use the echo or
printf command. For example:
$ echo $SHELL
/usr/bin/bash
$ printf "$PATH\n"
/usr/bin:/usr/sbin
Note -
Environment variables do not persist between sessions. To set up persistent environment
variable values, set the values in the
.bashrc file.
A shell can have two types of variables:
- Environment variables
-
Specifies variables that are exported to all processes that are spawned by the shell. The
export command is used to export a variable. For example:
export VARIABLE=value
These settings can be displayed by using the env command. A subset of
environment variables, such as PATH, affects the behavior of the shell
itself.
- Shell (local) variables
-
Specifies variables that affect only the current shell.
In a user initialization file, you can customize a user's shell environment by changing the
values of the predefined variables or by specifying additional variables.
The following table provides more details about the shell and environment variables that
are available in the Oracle Solaris release.
Table 1-10 Shell and Environment Variable Descriptions
|
|
|
Sets a variable that is used by the cd command. If the target directory of
the cd command is specified as a relative path name, the cd
command first searches for the target directory in the current directory (.).
If the target is not found, the path names that are listed in the CDPATH variable
are searched consecutively until the target directory is found and the directory change is
completed. If the target directory is not found, the current working directory is left unmodified.
For example, suppose the CDPATH variable is set to
/home/jean, and two directories exist under /home/jean,
bin, and doc. If you are in the
/home/jean/bin directory and type cd doc, you change
directories to /home/jean/doc, even though you do not specify a full
path.
|
|
Sets the path to the user's home directory.
|
|
Sets the locale.
|
|
Defines the name of the user that is currently logged in. The default value of
LOGNAME is automatically set by the login program to the user name that is
specified in the passwd file. You should only need to refer to, not reset, this
variable.
|
|
Sets the path to the user's mailbox.
|
|
Sets the hierarchies of man pages that are available.
Note -
Starting with Oracle Solaris 11, the MANPATH environment variable is
no longer required. The man command determines the appropriate
MANPATH based on the PATH environment variable setting.
|
|
Specifies, in order, the directories that the shell searches to find the program to run when
the user types a command. If the directory is not in the search path, users must type the complete
path name of a command.
As part of the login process, the default PATH is automatically
defined and set as specified in .profile.
The order of the search path is important. When identical commands exist in different
locations, the first command that is found with that name is used. For example, suppose that
PATH is defined in the shell syntax as
PATH=/usr/bin:/usr/sbin:$HOME/bin and a file named sample
resides in both /usr/bin and /home/jean/bin. If the user
types the command sample without specifying its full path name, the version that
is found in /usr/bin is used.
|
|
Defines the shell prompt for the bash or ksh93 shell.
|
|
Sets the default shell used by make, vi, and other
tools.
|
|
Names a directory where an alternate terminfo database is stored. Use the
TERMINFO variable in either the /etc/profile or
/etc/.login file. For more information, see the
terminfo
(4)
man page.
When the TERMINFO environment variable is set, the system first checks the
TERMINFO path defined by the user. If the system does not find a definition for a
terminal in the TERMINFO directory defined by the user, it searches the default
directory, /usr/share/lib/terminfo, for a definition. If the system does not
find a definition in either location, the terminal is identified as “dumb.”
|
|
Defines the terminal. This variable should be reset in either the
/etc/profile or /etc/.login file. When the user invokes an
editor, the system looks for a file with the same name that is defined in this environment variable.
The system searches the directory referenced by TERMINFO to determine the
terminal characteristics.
|
|
Sets the time zone. The time zone is used to display dates, for example, in the
ls -l command. If TZ is not set in the user's environment, the
system setting is used. Otherwise, Greenwich Mean Time is used.
|
|