Linux Environment Settings, Shell Selection and Startup Scripts
Linux 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|
|MANPATH||Sets the path for man pages|
Other environment variables include:
- 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".
- TERM - The type of terminal being used.
- PATH - The path the system looks in to find commands that the user has entered.
- HOME - The current user's home directory
- SHELL - The current shell program that is being executed
- USER - The name of the current user.
- TMPDIR - Allows programs that use the tempnam(3) function call to use the directory specified by this variable rather than the /tmp directory.
- 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.
- chsh -l
- 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.
The following scripts are run by bash if the ľnoprofile option is not used with the shell:
|/etc/profile ||This script file is run first for all users during the login process|
|$HOME/.bash_profile||This script file is run for individual user's customized setup|
|$HOME/.bash_login||If the .bash_profile above does not exist, this file is run|
|$HOME/.profile||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.
|$HOME/.bash_logout||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:
|/etc/bashrc||On my Redhat system, this file is run by $HOME/.bashrc.|
|/etc/login.defs||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:
|/etc/profile||For users environment setup and other customized items.|
|/etc/inputrc||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.