Running Commands from the Shell
computer software
Running Commands from the Shell Running Commands from the Shell
Running Commands from the Shell   Home | Site Map | About Us | Products | Services | News | Contact Us | Links Running Commands from the Shell
Running Commands from the Shell Running Commands from the Shell

Copyright © 2009

Linux® Bible


that file that you can modify. Refer to the Bash Prompt HOWTO (
www·tldp·org/HOWTO/Bash-
Prompt-HOWTO
) for information on changing colors, commands, and other features of your bash
shell prompt.
Adding Environment Variables
You may consider adding a few environment variables to your
.bashrc
file. These can help make
working with the shell more efficient and effective:
TMOUT
-- Sets how long the shell can be inactive before bash automatically exits. The
value is the number of seconds for which the shell has not received input. This can be a
nice security feature, in case you leave your desk while you are still logged in to Linux. So
as not to be logged off while you are working, you may want to set the value to some-
thing like
TMOUT=1800
(to allow 30 minutes of idle time). You can use any terminal ses-
sion to close the current shell after a set number of seconds -- for example,
TMOUT=30
.
PATH
-- As described earlier, the
PATH
variable sets the directories that are searched for
commands you use. If you often use directories of commands that are not in your PATH,
you can permanently add them. To do this, add a PATH variable to your
.bashrc
file.
For example, to add a directory called
/getstuff/bin
, type the following:
PATH=$PATH:/getstuff/bin ; export PATH
This example first reads all the current path directories into the new PATH (
$
PATH), adds
the
/getstuff/bin
directory, and then exports the new PATH.
Some people add the current directory to their PATH by adding a directory identified
simply as a dot (
.), as follows:
PATH=.:$PATH ; export PATH
This enables you always to run commands in your current directory before evaluating any other com-
mand in the path (which people may be used to if they have used DOS). However, the security risk
with this procedure is that you could be in a directory that contains a command that you don't intend
to run from that directory. For example, a malicious person could put an
ls command in a directory
that, instead of listing the content of your directory, does something devious. Because of this, the
practice of adding the dot to your path is highly discouraged.
WHATEVER
-- You can create your own environment variables to provide shortcuts in
your work. Choose any name that is not being used and assign a useful value to it. For
example, if you do a lot of work with files in the
/work/time/files/info/memos
directory, you could set the following variable:
M=/work/time/files/info/memos ; export M
You could make that your current directory by typing
cd $M
. You could run a program
from that directory called
hotdog
by typing
$M/hotdog
. You could edit a file from there
called
bun
by typing
vi $M/bun
.
CAUTION
CAUTION
59
Running Commands from the Shell
2