Index->Environment Variables & Startup FilesEnvironment Variables & Startup Files
In this lab, we will experiment with a few additional tricks
in Linux. Linux maintains several variables that affect what
you can do at the command line.
Command Prompt
- Check your PS1 variable by typing "echo
$PS1"
- Reset your prompt temporarily, by typing PS1="CIS rules> "
Search Path
Linux searches for the location of any command you enter. It
needs to know in which directories to look. The PATH
environment variable contains a list of directories.
- Check your PATH variable, "echo $PATH".
Notice that each of the distinct directories are separated by
a colon.
- Try to run the C program 'myFirst' from last lab
without putting the 'dot slash' in front. Linux can not find
the correct command because your current directory is not in
your search path.
- Modify the search path so that Linux will look in your
current directory, type PATH=$PATH:. (note the colon
after the second PATH name). This command tells Linux to take
the original PATH, add the current directory to it,
and then reassign it to the original PATH. As a last
resort, Linux will look in your current directory for a
program to execute.
- Check your PATH variable again. See the colon at
the end?
- Now try to run your first C program again.
Aliases
You can customize some commands that you often use. An alias
is a command created by you that is often a shortcut for longer
commands.
- List your current aliases by typing, "alias". Note that
some have been created for you already.
- Now create your own, "alias c=cal"
- Now type 'c' and press return
- Now create a second alias, "alias x='ls -al'"
- Now type 'x' and press return
Remote Access
- Try "who". This lists every user that is currently logged
into your computer. It might just be you or could also be
several other people that have remotely logged on.
- Try "ssh". This is a more secure version of 'telnet'. It
allows you to remotely connect to any computer on the
Internet if you have an account. Connect your neighbor's
computer in the lab using the appropriate computer name such
as "ssh eos12.cis.gvsu.edu". You should be able to log into
the machine.
- Try "who" again after your neighbor computer is connected
to your machine.
- Log out of the other machine, "exit".
Start Up Files
Taking the time to customize aliases and environment
variables does not seem to help much if they reset each time
you log out. Fortunately, you can place these customizations
into a special file that is called automatically every time you
log in. On our system, one of the special files is called
".bashrc". Note that it begins with a period.
- In your home directory, make a backup of your bashrc
file, "cp .bashrc .bashrc.bak"
-
Edit your original .bashrc file using a text editor such as vi.
Add a line for each alias you want to create. Such as:
alias h='history'
alias p='ps -a'
- Add your name at the top in a comment field and save the
file
-
Manually execute your .bashrc file using the dot command
. .bashrc
-
Check your aliases by typing
alias
-
If you choose to modify your path so that you can run files
in your current directory, make sure you place it after the
if statement that is already in the file.
export PATH=$PATH:.
- Print your .bashrc file with your name in it and at least
one additional alias. Hand in your printout to your
instructor.
|