Sunteți pe pagina 1din 19

How to set Shell Environment Variables (bash shell)

In Linux the command line interpreter is known as the shell. Whatever you type at the
command line is understood and interpreted by a program and then that program gives
you an output after executing your command. This program that understands what you
type is called the shell.

Linux comes with quite a few shells such as Bourne Shell, Bourne Again Shell, C Shell,
Korn Shell, etc. The default shell for Redhat Linux is ' bash ' which is very popular since
being the default, most users start by learning bash. I shall talk about the bash shell only
in this article.

Windows users would be familiar with a program called command.com which had to be
present for the OS to boot. Command.com is the Windows equivalent of the Linux shell.

Typing the following at the shell

$ echo $SHELL

would give you the name of the current shell you are using. It would most probably be
the bash shell in case you are a new user and have been assigned the default shell.

The bash shell is actually a program that is located at /bin/bash and is executed by Linux
the moment a user successfully logs in after entering his user-pass. Once this shell starts,
it takes over control and accepts all further user commands. The bash shell presents a $
prompt by default (for normal user accounts). You can change this prompt to whatever
you like but leaving it at the default is best. Other shells present different prompts.
Changing the prompt is explained below.

-
Tarno
misno
abram
teguh
angg
anggi
vespa
abram
Shell Environment

All the programs that run under Linux are called as processes. Processes run continuously
in Linux and you can kill or suspend different processes using various commands. When
you start a program a new process is created. This process runs within what is called an
environment. This particular environment would be having some characteristics which
the program/process may interact with. Every program runs in its own environment. You
can set parameters in this environment so that the running program can find desired
values when it runs.

Setting a particular parameter is as simple as typing VARIABLE=value . This would set


a parameter by the name VARIABLE with the value that you provide.

To see a list of the environment variables that are already set on your machine, type the
following

$ env

This would produce a long list. Just go through the list before reading the next part of the
article. Linux by default sets many environment variables for you. You can modify the
values of most of these variables. A few of the variables that are set are

HOME=/home/david
would set the home directory to /home/david. This is perfect in case your login name is
david and you have been given a directory named /home/david . In case you don't want
this to be your home directory but some other one you could indicate so by typing the
new directory name. The HOME directory is always the directory that you are put in
when you login.

There are many advantages of using the HOME variable. You can always reach your
home directory by only typing ' cd ' at the prompt, irrespective of which directory you are
presently within. This would immediately transfer you to your HOME directory. Besides
in case you write scripts that have $HOME present in them to refer to the current HOME
directory, these scripts can be used by other users as well since $HOME in their case
would refer to their home directories.
-

PATH=/usr:/bin/:usr/local/bin:.
This is a very important environment variable. This sets the path that the shell would be
looking at when it has to execute any program. It would search in all the directories that
are present in the above line. Remember that entries are separated by a ' : ' . You can add
any number of directories to this list. The above 3 directories entered is just an example.

Note : The last entry in the PATH command is a ' . ' (period). This is an important
addition that you could make in case it is not present on your system. The period
indicates the current directory in Linux. That means whenever you type a command,
Linux would search for that program in all the directories that are in its PATH. Since
there is a period in the PATH, Linux would also look in the current directory for program
by the name (the directory from where you execute a command). Thus whenever you
execute a program which is present in the current directory (maybe some scripts you have
written on your own) you don't have to type a ' ./programname ' . You can only type '
programname ' since the current directory is already in your PATH.

Remember that the PATH variable is a very important variable. In case you want to add
some particular directory to your PATH variable and in case you try typing the following

PATH =/newdirectory

This would replace the current PATH value with the new value only. What you would
want is to append the new directory to the existing PATH value. For that to happen you
should type

PATH=$PATH:/newdirectory

This would add the new directory to the existing PATH value. Always a $VARIABLE is
substituted with the current value of the variable.

PS1=boss

PS1 is the shell prompt. It defines what you want your shell prompt to look like. By
default it looks like a ' $ ' in bash shell. The above case would replace the default ' $ ' with
a new 'boss' . Hence an ls command would look something like

Tarno
misno
abram
teguh
angg
anggi
vespa
abram
boss> ls

All your commands would now be typed at a ' boss ' prompt instead of a ' $ ' prompt.

SHELL=/bin/bash

This tells where the program that represents your shell is to be found. In case you
typed /bin/ksh in the above, then your bash shell would be replaced with the ksh shell
(korn shell). So in case you are not happy with the bash shell, you could replace the bash
with some other shell.

LOGNAME=david

The LOGNAME is automatically set for you as the same as your login name. This
variable is used in case you want to use your own login name in any script. This is the
simplest way of getting your login name from within a script. Thus in case you use
$LOGNAME in any script the script would work for all users since the LOGNAME
always holds the name of the current user.
A good use is in case you have been given a temporary directory to work with and to
make temporary files then you would want to delete the files that you created. You could
use a command with the $LOGNAME in it to locate files that were created by you and
then you could pass the result of this command to a rm command. This would be a neat
way to delete all the files at one go, rather than find them one at a time.

Note : Finding files based on a particular criteria and then passing those files to another
program is explained in Article No. 21
-

There are more environment variables then the ones that are mentioned here. But most
users would find the ones given here to be useful.
Important : To make the above changes permanent (that is it should work every time you
login) make the changes to the .profile file that exists in your HOME directory. Simply
type the required commands one line for each. And there you go. It will be available
every time you login. You could check the variables using 'env' command.

How To Set Up An AAA Server With CIITIX-WiFi


Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Submitted by babarsaleem (Contact Author) (Forums) on Fri, 2010-06-04 16:32. :: Linux
How To Set Up An AAA Server With CIITIX-WiFi

CIITIX-WiFi is a turnkey solution to your WiFi hotspot needs. Built onto the rock solid
stable debian linux, setting up a secure (TTLS) WiFi hotspot is just a minute away. This
guide shows how to set up an AAA server (authentication, authorization and accounting)
with CIITIX-WiFi.

* Download CIITIX-WiFi image from here.


* Burn the image to CD.
* Insert The CIITIX-WiFi CD into CDROM and power-on your PC. Select Boot from
CDROM.
* At the Boot Prompt press Enter.

* Select Start CIITIX-WiFi Live if you want to run CIITIX live-CD or Start GUI
Install if you prefer to install it and go with GUI install environment.

* On the X login prompt use the user ciitix & password live.
* Fire up the browser. Log into the GUI front-end with administrator user name &
radius as the password.

* Add the user in the DB from the section displayed in the screen-shot (Management >
Users under Users Management > New User). Note: Don't forget to select Cleartext-
Password as Password Type.

* Add the NAS device in the DB from the section displayed in the screen-shot
(Management > Nas under NAS Management > New NAS).

* Restart the freeradius as follows:

sudo /etc/init.d/freeradius restart

* Copy/install the client certificates onto the clients (copy from


/etc/freeradius/certs/client-certificates folder i.e. ca.der & server.p12). Note: Install them
in trusted root certificates section so as not to receive any warnings since they are self-
signed & not verisign signed. Password for server.p12 certificate is ciitixwifi.

Congratulations, you have set up a wifi server in under 5 minutes.

Copyright © 2010 Babar Saleem


All Rights Reserved.
add comment | view as pdf view as pdf | Display a printer-friendly version of this page.
print |
Please do not use the comment function to ask for help! If you need help, please
use our forum.
Comments will be published after administrator approval.
Sponsored Links: Turn your desk phone and mobile phone into one with Sprint Mobile
Integration.
www.seamlessenterprise.com

One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com

One Number. One Voicemail.


Make it easier for clients to reach you. Turn your desk phone and mobile phone into one
with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Sprint Mobile Integration.


www.seamlessenterprise.com

AT&T Synaptic Compute as a Service. Boost your power on demand.


Trial: IBM Cognos Express Reporting, Analysis & Planning

Learn benefits of Simpana software.


View the Gartner Video

Sprint 4G - The Ultimate Mobile Broadband


Click here

SAP-Business Objects Crystal Reports Server


Complete reporting without hidden costs. Free Trial
Howtos | Mini-Howtos | Forums | News | Search | Contribute

| Subs

S-ar putea să vă placă și