Previous Page | Next Page

  1. Introduction
  2. About Linux
  3. Installation and getting started
  4. Logging in and out
  5. Basic Linux Commands
  6. Linux Files and File Permissions
  7. Linux Directory Structure
  8. Finding Files
  9. Linux Help
  10. Setting Time
  11. Devices
  12. Tips
  13. Accessing Other Filesystems
  14. Accessing Removable Media
  15. Making and Managing Filesystems
  16. Emergency Filesystems and Procedures
  17. LILO and Runlevels
  18. Init
  19. Environment, Shell Selection, and Startu
  20. Linux Kernel
  21. Package Installation and Printing
  22. Configuration, Logging and CRON
  23. Keys and Terminal Configuration
  24. Sound Configuration
  25. Managing Users
  26. Passwords
  27. Process Control
  28. Configuration and Diagnostic Tools
  29. Overall Configuration
  30. Using PAM
  31. Basic Network Setup
  32. Tools and Terms
  33. Novell and Printing
  34. Inetd Services
  35. Xinetd Services
  36. Other Network Services
  37. FTP and Telnet
  38. Samba
  39. Identd (auth)
  40. X Configuration
  41. X Use
  42. Using X Remotely
  43. X Documentation
  44. DNS
  45. DHCP and BOOTP
  46. Apache
  47. NFS
  48. PPP
  49. Mail
  50. Routing
  51. IP Masquerading
  52. Proxy Servers and ipchains
  53. UUCP
  54. News
  55. NIS
  56. Network Security
  57. Secure Shell
  58. Text Processing
  59. Shell Programming
  60. Emacs
  61. VI
  62. Recommended Reading
  63. Credits

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/sbinAdds /usr/sbin to the path in the system environment
MANPATHSets the path for man pages

Other environment variables include:

  1. USERNAME
  2. HOSTNAME
  3. LOGNAME
  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:

/bin/bash
/bin/sh
/bin/tcsh
/bin/csh
/bin/ash
/bin/bsh
/bin/bash2
/bin/ksh
/bin/zsh

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:

/etc/profile This script file is run first for all users during the login process
$HOME/.bash_profileThis script file is run for individual user's customized setup
$HOME/.bash_loginIf the .bash_profile above does not exist, this file is run
$HOME/.profileThis 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_logoutRun 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/bashrcOn my Redhat system, this file is run by $HOME/.bashrc.
/etc/login.defsUsed 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/profileFor users environment setup and other customized items.
/etc/inputrcFor 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.