The Bash Shell,continued...
Environment Variables
If you have any programming experience
at all, or you have been reading the Guides like a good little
hacker, then you will know about Variables. Think of these as
named pieces of your computer's memory which hold values. Depending
upon the variables in question, you may or may not have immediate
control of their contents.
Another concept is your environment, which is
what you find when you give the "env" command. Much
like the real world you live in, your environment in your shell
stores information such as the operating system you are running,
the version, your home directory, a list of directories to look
at when you want to run a program, and so on.
Some of the more common bash environment variables
that you will want to know a bit about are:
PATH
this is a colon-separated list
of directories which bash uses to
search for commands. eg:
/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/newstuff/progs
HOME
the current users home directory,
eg:
/home/bob
CDPATH
a colon-seperated list of directories
to search when you issue the
cd command, eg:
/home:/usr/local/etc:/usr/local/games
if you had a directory under /usr/local/etc
called myGreatProg, you could issue a cd myGreatProg on
the command line and you would be taken to the first occurrence
of myGreatProg in CDPATH. In this case, /usr/local/etc/myGreatProg.
When it comes down to it, this is not necessary, it's just a
nicety which can confuse you at times. Use with care!
MAILPATH
a colon-separated list of spool
files which bash checks periodically for new mail, eg:
/usr/spool/mail/bob:/var/spool/bob
PS1 & PS2
primary and secondary prompt strings.
The primary prompt is used at your standard interactive shell.
ie; when you log in or you run bash.
The secondary prompt is used when bash needs more input
to complete a command. for example, at the prompt, type:
cd \
bash will change the prompt
to ">" or whatever your PS2 is set to, indicating
that you need to type more before it can execute your instruction.
Try typing:
~
and after you press ENTER,
the complete command will have been "cd ~".
This takes you to your home directory.
The backslash "\" indicated that the command continues
on the next line. This can be used in your scripts as well for
long lines that you don't want to get too messy.
RANDOM
This is a nice variable which
you can call upon to give you a random number. Assigning a number
to this will allow you to generate a seed. This is a nifty idea,
but unfortunately, it is not entirely random. After executing
this a few times, I noticed a pattern, so if you are going to
use It, take care. Mind you, if you were going to write some
really flash crypto routine, then you'd probably be using a programming
language as opposed to a
scripting language :)
To set variables, you can use the set command,
eg:
set TEMP_VAR=cheese
But this will not export it into the environment
in bash. to do that, you must use export, eg:
xport TEMP_VAR
You can, however, just use export, thus:
export TEMP_VAR=cheese
More on the bash shell --->>