OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

See Chapter 9 for more on the actual compressing of files and examples on making archives.


image


7.2. Your text environment


7.2.1. Environment variables


7.2.1.1. General


We already mentioned a couple of environment variables, such as PATH and HOME. Until now, we only saw examples in which they serve a certain purpose to the shell. But there are many other Linux utilities that need information about you in order to do a good job.


What other information do programs need apart from paths and home directories?


A lot of programs want to know about the kind of terminal you are using; this information is stored in the TERM variable. In text mode, this will be the linux terminal emulation, in graphical mode you are likely to use xterm. Lots of programs want to know what your favorite editor is, in case they have to start an editor in a subprocess. The shell you are using is stored in the SHELL variable, the operating system type in OS and so on. A list of all variables currently defined for your session can be viewed entering the printenv command.


The environment variables are managed by the shell. As opposed to regular shell variables, environment variables are inherited by any program you start, including another shell. New processes are assigned a copy of these variables, which they can read, modify and pass on in turn to their own child processes.


There is nothing special about variable names, except that the common ones are in upper case characters by convention. You may come up with any name you want, although there are standard variables that are


important enough to be the same on every Linux system, such as PATH and HOME.


image

7.2.1.2. Exporting variables


An individual variable's content is usually displayed using the echo command, as in these examples:


debby:~> echo $PATH

/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin


debby:~> echo $MANPATH

/usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man

debby:~> echo $PATH

/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin


debby:~> echo $MANPATH

/usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man

If you want to change the content of a variable in a way that is useful to other programs, you have to export the new value from your environment into the environment that runs these programs. A common example is exporting the PATH variable. You may declare it as follows, in order to be able to play with the flight simulator software that is in /opt/FlightGear/bin:


debby:~> PATH=$PATH:/opt/FlightGear/bin This instructs the shell to not only search programs in the current path, $PATH, but also in the additional directory /opt/FlightGear/bin.


However, as long as the new value of the PATH variable is not known to the environment, things will still not work:


debby:~> runfgfs

bash: runfgfs: command not found

debby:~> runfgfs

bash: runfgfs: command not found

Exporting variables is done using the shell built-in command export:


debby:~> export PATH


debby:~> runfgfs

--flight simulator starts--

debby:~> export PATH


debby:~> runfgfs

--flight simulator starts--

In Bash, we normally do this in one elegant step:


export VARIABLE=value


The same technique is used for the MANPATH variable, that tells the man command where to look for compressed man pages. If new software is added to the system in new or unusual directories, the documentation for it will probably also be in an unusual directory. If you want to read the man pages for the new software, extend the MANPATH variable:


debby:~> export MANPATH=$MANPATH:/opt/FlightGear/man


debby:~> echo $MANPATH

/usr/man:/usr/share/man:/usr/local/man:/usr/X11R6/man:/opt/FlightGear/man

debby:~> export MANPATH=$MANPATH:/opt/FlightGear/man


debby:~> echo $MANPATH

/usr/man:/usr/share/man:/usr/local/man:/usr/X11R6/man:/opt/FlightGear/man

You can avoid retyping this command in every window you open by adding it to one of your shell setup files, see Section 7.2.2.


image

7.2.1.3. Reserved variables


The following table gives an overview of the most common predefined variables:


Table 7-1. Common environment variables


Variable name

Stored information

DISPLAY

used by the X Window system to identify the display server

DOMAIN

domain name

EDITOR

stores your favorite line editor

HISTSIZE

size of the shell history file in number of lines

HOME

path to your home directory

HOSTNAME

local host name

INPUTRC

location of definition file for input devices such as keyboard

LANG

preferred language

LD_LIBRARY_PATH

paths to search for libraries

LOGNAME

login name

MAIL

location of your incoming mail folder

MANPATH

paths to search for man pages

OS

string describing the operating system

OSTYPE

more information about version etc.


PAGER

used by programs like man which need to know what to do in case output is more than one terminal window.

PATH

search paths for commands

PS1

primary prompt

PS2

secondary prompt

PWD

present working directory

SHELL

current shell

TERM

terminal type

UID

user ID

USER(NAME)

user name

VISUAL

your favorite full-screen editor

XENVIRONMENT

location of your personal settings for X behavior

XFILESEARCHPATH

paths to search for graphical libraries

A lot of variables are not only predefined but also preset, using configuration files. We discuss these in the next section.


image


7.2.2. Shell setup files


When entering the ls -al command to get a long listing of all files, including the ones starting with a dot, in your home directory, you will see one or more files starting with a . and ending in rc. For the case of bash, this is .bashrc. This is the counterpart of the system-wide configuration file /etc/bashrc.


When logging into an interactive login shell, login will do the authentication, set the environment and start your shell. In the case of bash, the next step is reading the general profile from /etc, if that file exists. bash then looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, /etc/bashrc is applied.


image

Top OS Cloud Computing at OnWorks: