Environment Settings, Shell Selection and Startup Scripts

Environment Variables and Settings

There are many environment variables, some of which are listed below. The command used to add or modify environment variables is the export builtin command provided by the bash shell. See the bash(1) man page for more information on this built in command.
PS1="[\u@h \w]\\$ "

Used to set the command line string to output user,machine and name of directory the user is in. In Redhat, to effectively change this value, it must be changed in the file "/etc/bashrc" and in "/etc/profile".
export PATH=$PATH:/usr/sbin

Adds /usr/sbin to the path in the system environment

Sets the path for man pages
Other environment variables include:
  4. MAIL
  5. EDITOR - Specifies the editor to be used by default for some commands such as edquota. Usually it is set to vi or emacs with a command like "export EDITOR=emacs".
  6. TERM - The type of terminal being used.
  7. PATH - The path the system looks in to find commands that the user has entered.
  8. HOME - The current user's home directory
  9. SHELL - The current shell program that is being executed
  10. USER - The name of the current user.
  11. TMPDIR - Allows programs that use the tempnam(3) function call to use the directory specified by this variable rather than the /tmp directory.
  12. SHLVL - Shows how many shells the user has invoked.
You can type "env" to see a listing of all current environment variables.
SHLVL indicates how many shells deep the user is. If the level is 2, you must type "exit", then logout to exit.
Setting noclobber=1 - keeps files from being clobbered by the shell.

Shell Selection for users

The file "/etc/shells" lists the valid shells and shell paths on your system. An example file is:
The command "chsh" can be used by the user to set his preferred shell. Also the root user can use this command to set any user's shell. This command with the -l option will list the available shells. The -s option will allow the user to change their shell. For example type the following to determine and modify the user's shell.
  1. chsh -l
  2. chsh -s /bin/sh
The first line will show available shells, and the second entry will change it. The full path of the shell must be entered for the command to work.

Startup Scripts

The following scripts are run by bash if the –noprofile option is not used with the shell:

This script file is run first for all users during the login process

This script file is run for individual user's customized setup

If the .bash_profile above does not exist, this file is run

This script file is run if $HOME/.bash_profile and .bash_login don't exist
If bash is invoked as "sh" it will run only "/etc/profile" and "$HOME/.profile", above.
The man page says that "$HOME/.bashrc" is run for non-login interactive shells. I'm not sure if it also runs for login interactive shells, but believe it does. If it does, I'm not sure whether it is run after the scripts above, but believe it is.


Run when the user logs off the system.

Key bindings:
If the shell variable "INPUTRC" is set, probably in "/etc/profile" the keybindings are set by the file declared in the INPUTRC value. Usually this is "/etc/inputrc". Otherwise the keybindings are set in the file "$HOME/.inputrc" for each individual user.
$HOME/.inputrc - User's keybindings definition
/etc/inputrc - Global keybindings definition
Other scripts and files:

On my Redhat system, this file is run by $HOME/.bashrc.

Used with shadow passwords to set initial PATH and other parameters including how often a user must change passwords and what is acceptable as a password..

Put any new script files in /usr/bin or /usr/local/bin. If you put them in /usr/local/bin, they will be easier to keep track of, but you may want to add /usr/local/bin to your path environment to make them more accessible. You can put the command "export PATH=$PATH:/usr/local/bin" in one of the above scripts or add it to the path statement in /etc/profile.
Therefore to modify parameters for all users, edit:

For users environment setup and other customized items.

For keybindings on some systems if INPUTRC is set to it.

To customize user's setup edit: (Note: In /home/user's name/...)
HOME/.bash_profile - Users environment stuff and startup programs
$HOME/.bashrc - user aliases and functions
$HOME/.bash_logout - User actions to be done at logout
$HOME/.inputrc - Contains keybindings and other bits.
The tcsh shell operates as follows:
/etc/csh.login is run
$HOME/.tcshrc or .cshrc is run
$HOME/.login is run
Other files in the users home directory may be:
.emacs - For the emacs editor. Consists of LISP functions.
.exrc - For the vi editor
.fvwmrc - For the fvwm window manager
.twmrc - For the twm window manager
.newsrc - For newsreaders. Contains a list of newsgroups offered at this site.
.Xdefaults - For programs using the X window system
.xinitrc - Shell commands that run when the user logs into an X session.


Post a Comment