Looking at Your bash Configuration Files

Looking at Your bash Configuration Files

Your first step in modifying or adding bash environment variables in your configuration files is to look at the configuration files, which show you the variables that have been defined. As Code Listing 8.10 shows, you do this using more or the editor of your choice.

Remember that configuration files run in a specific order:

  • Systemwide configuration files (such as /etc/profile) run first upon log in.

  • Configuration files specific to your Unix account (such as ~/.bash_profile or ~/.profile) run next if they're available.

To look at your bash configuration files:


more ~/.bash* ~/.profile  /etc/bash* /etc/profile 

At the shell prompt, type more followed by each of the possible system configuration filenames to view your configuration files. If you don't have all of the files mentioned here, don't worry. Just make note of the ones you do have. Code Listing 8.10 shows an example of what you might see. Notice that some of the lines will reference other files, like the ENV=$HOME/.bashrc line that references the .bashrc file, containing other configuration settings.

Code Listing 8.10. Your configuration files set up your environment variables and other features of your Unix experience.

[ejr@hobbes ejr]$ more ~/.bash* ~/.profile /etc/bash* /etc/profile :::::::::::::: /home/ejr/.bash_profile :::::::::::::: # .bash_profile # Get the aliases and functionsif [ -f ~/.bashrc ]; then     . ~/.bashrc fi # User-specific environment and startup programs PATH=$PATH:$HOME/bin ENV=$HOME/.bashrc USERNAME="" export USERNAME ENV PATH /home/ejr/.profile: No such file or directory :::::::::::::: /etc/bashrc :::::::::::::: # /etc/bashrc # System-wide functions and aliases # Environment stuff goes in /etc/profile # Putting PS1 here ensures that it gets loaded every time. PS1="[\u@\h \W]\\$ " alias which="type -path" :::::::::::::: /etc/profile :::::::::::::: # /etc/profile # System-wide environment and startup programs # Functions and aliases go in /etc/bashrc PATH="$PATH:/usr/X11R6/bin" PS1="[\u@\h \W]\\$ " ulimit -c 1000000 if [ 'id -gn' = 'id -a 'id -u' -gt 14 ]; then     umask 002 else     umask 022 fi USER='id -un' LOGNAME=$USER MAIL="/var/spool/mail/$USER" HOSTNAME='/bin/hostname' HISTSIZE=1000 HISTFILESIZE=1000 export PATH PS1 HOSTNAME HISTSIZE HISTFILESIZE USER LOGNAME MAIL for i in /etc/profile.d/*.sh ; do     if [ -x $i ]; then     . $i     fi done unset i [ejr@hobbes ejr]$ 


Write down, for your reference, the system configuration files and the order in which they're run. (Remember, settings in the last file run override all previous ones.) Our system configuration files include

  • /etc/profile (automatically called by the system if it exists)

  • ~/.bash_profile (automatically called by the system if it exists)

  • ~/.bashrc (automatically called by the system if it exists)

  • /etc/bashrc (often called by


  • ~/.bashrc (automatically called by the system if it exists)

Keep in mind that the files you have may differ from the files that we have.


  • The bash shell sometimes daisychains configuration files together, referencing one from the previous one. Be careful to preserve the references and sequence as you edit your configuration files, or you might end up with unexpected results.

  • All lines that start with # are comments, which contain notes to help you better understand the files. Comments don't actually do anything, but they help you see what each section in the file does.

  • The techie term (that you'll likely see in these files) for executing a configuration file or a script is to source it. That is, when you log in, your .profile may source .kshrc.

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net