Table of Contents
When a Unix system starts up a series of scripts are run which set the operating system up, eventually the user will be presented with the familiar login prompt or equivalent. Upon logging in some script(s) are executed which set up the working environment. The particular script(s) executed will depend on the default shell.
A Unix shell is an interface for controlling a Unix system. There are quite a few different shells out there, some of them have similar syntax', some of them vary in their syntax'. The most commonly used Unix shells are SH(Bourne SHell), CSH(C SHell), RSH(Restricted SHell) and KSH(Korn SHell). It is very likely that at least one of these shells will be available on the Unix system you are using. There are also a number of other shells available to the Unix user such as BASH(Bourne Again SHell), TCSH(Enhanced C SHell) and ZSH(Z SHell).
I am not going to go into depth about the various merits of using one shell over another, this is already covered in detail at http://www.nscp.umd.edu/shells.html or alternatively in the FAQ posted to the newsgroup comp.unix.shell monthly, also a place where you can discuss the idiosyncrasies of Unix shellism to your hearts content.
You can find out what shell you are using by issuing the commands
echo $SHELL |
. If you are using CSH or some variant the scripts executed at login will be .login and .cshrc these are situated in the users home directory described by the HOME environment variable which will be explained later. If you are using SH or some variant the script executed at login will be .profile. Any settings in this/these file(s) will effect the user whom owns them. The file(s) is/are used to setup the working environment for the user who owns them. If you start a new shell from within another shell, the new shells startup files will be executed. In addition, if you are using CSH .cshrc will be executed every time a further instance of CSH is invoked.
The environment contains variables called environment variables which contain information that is useful or essential for the Unix operating system to function as the user expects it to. An example environment variable is the PATH environment variable which contains a colon separated list of directories indicating where the Unix operating system expects executable programs to be found. When a command is typed into the shell, the Unix operating system will search through the directories listed in the PATH environment variable in the order they occur until it either finds an executable matching the command typed or fails to find a match. A few other examples of environment variables found on the Unix operating system are listed below:
EDITOR: Specifies the default editor.
PWD: Specifies the current working directory.
USER: Specifies the current user.
SHELL: Specifies the default shell.
RANDOM: Contains a random integer which changes each time the variable is referenced.
![]() | Note |
|---|---|
TCSH uses the configuration file .tcshrc instead of .cshrc | |
If you are using CSH or some variant you can change environment variables temporarily from the command line using the following syntax:
setenv VARIABLENAME value_of_variable |
The changes will remain in effect until you logout or invoke a new shell. If you would like to change an environment variable permanently you should edit the file .cshrc and insert the line:
setenv VARIABLENAME value_of_variable
|
The changes will come into effect the next time you login or invoke an instance of CSH if you cannot wait that long, you can type
source .cshrc |
to put the changes into effect immediately. It can be useful to append to the end of an environment variable, this can be achieved using the following syntax at the command line and within .cshrc:
setenv VARIABLE ${VARIABLE}:value_to_append
|
This will append :value_to_append to the end of the current value of the variable. In the example above the character ':' has been placed between ${VARIABLE} and value_to_append, this is not mandatory but has been included to illustrate that this type of setting of environment variables which appends to the variable is often used to add a directory to a list of directories or a file to a list of files, when this is the case ':' is the standard separator used.
If you are using SH or some variant you can change environment variables temporarily from the command line using the following syntax:
export VARIABLENAME=value_of_variable |
The changes will remain in effect until you logout or invoke a new shell. If you would like to change an environment variable permanently you should edit the file .profile and insert the line:
VARIABLE=value_of_variable EXPORT VARIABLE |
The changes will come into effect the next time you login or invoke an instance of SH if you cannot wait that long, you can type
. .profile |
to put the changes into effect immediately. It can be useful to append to the end of an environment variable, this can be achieved using the following syntax from the command line:
EXPORT VARIABLE=$VARIABLE:value_to_append |
And from within .profile:
VARIABLE=$VARIABLE:value_to_append
EXPORT VARIABLE
|
This will append :value_to_append to the end of the current value of the variable. In the example above the character ':' has been placed between ${VARIABLE} and value_to_append, this is not mandatory but has been included to illustrate that this type of setting of environment variables which appends to the variable is often used to add a directory to a list of directories or a file to a list of files, when this is the case ':' is the standard separator used.
There are generally two ways of installing software on Unix:
Install from pre-packaged distribution dependent medium such as RPM, PKG or BIN.
Compile and install from source files.
RPM (RPM Package Manager) is an easy to use package management system under the GPL license. The homepage is http://www.rpm.org/. An RPM search engine can be found at http://rpmfind.net/. It is only necessary to know a few simple commands to use RPM:
rpm -i somepackage.rpm |
Installs the package specified.
rpm -e somepackage |
Removes the package specified.
rpm -i ftp://blah/blah/blah/somepackage.rpm |
Installs an RPM from some URL.
rpm --help |
Displays the builtin help.
Additional help for installing RPMs can be found at http://www.rpm.org/RPM-HOWTO/. If you are using FreeBSD, you can benefit from using the ports system, explained at http://www.freebsd.org/ports/index.html.
Occasionally a program may only be available in source format, or you may desire to have the very latest version, which has not yet been packaged, if this is the case you will have to install from the sources. Source code usually comes in a gzipped tar archive (*.tar.gz), this will need to be extracted to a temporary directory somewhere:
tar xzvf blah.tar.gz
|
Will extract the gzipped tar archive to the current directory. cd to the directory created (something like blah-1.4.2). This directory should contain a file called INSTALL detailing how to compile and install the program, you should follow the instructions contained therein, generically one installs from source like this:
./configure |
To configure the installation for your machine.
make |
To build the binary files.
make install |
To install the binaries in some suitable location, for example, /usr/local/bin/.
![]() | Note |
|---|---|
This procedure assumes a c-based program, increasingly, programs are being made entirely in Java and so this installation procedure does not apply. Instead, follow the instructions that come with the downloaded program. | |