=================================================== Setting up Startup Files: .bash_profile and .bashrc =================================================== -Ian! D. Allen - idallen@idallen.ca - www.idallen.com Loading shell defaults, options, aliases, and functions is done when the shell first starts. You can change things while the shell is running, but the changes are *not* saved. Start-up files are places to save things so that every new shell gets them. All startup file references are to files in your home directory, which is where "cd" takes you without arguments. Your home directory is also usually available in the environment variable "$HOME". $HOME/.bash_profile: If you use a Linux system (e.g. RedHat, Knoppix, Ubuntu, Fedora, etc.), your login shell is already BASH and it reads ("sources") the .bash_profile file (instead of .profile) when you log in. As with .profile, .bash_profile is only read once by the login shell, not by any other shells you might start up after you log in. You can put things in this file that need to be done exactly once at login and that are inherited by other shells: - set (and export) PATH and/or TERM - set umask - set your erase character (backspace character) - set your prompt PS1 (and export it: export PS1) Any aliases you define in these login profile files will apply *only* to the BASH shell at login, not to any other shells you start. Better to define aliases in your $HOME/.bashrc file. If you find that a nested shell is not inheriting PATH, TERM, or PS1, you must "export" the variable, e.g. "export PS1". To define aliases and options, use the other start-up file: $HOME/.bashrc: Put things in this file that don't get inherited from parent shells. Every BASH shell reads ("sources") .bashrc when it first starts up. Every new BASH shell reads this file, unless you use the "--norc" option when you start it. Any aliases and options you define in .bashrc will apply to all BASH shells, including your login shell. Set your personal bash aliases and functions, e.g. alias cd..='cd ..' Set your own useful shell options. I recommend these: - shopt -s failglob - set -o ignoreeof -o noclobber -o notify -o nounset -o physical - set -o interactive-comments shopt -s failglob - Give an error message if a GLOB fails to match any pathnames set -o ignoreeof - The shell will ignore ^D (EOF) at the prompt; use "exit" to exit set -o noclobber - Protects files from being overwritten when ">" redirection is used - Use the "force" syntax ">|" to force overwriting, e.g. date >| foo set -o notify - Notifies user immediately when a background job ("&") completes set -o nounset - Displays an error when expanding a variable that has not been set set -o physical - Expand all symbolic links in output of pwd and when using cd set -o interactive-comments - Allow "#" to comment out any following text, e.g. echo a b # not seen Refer to the bash man page for details. What happens when you Log In? ============================= When you type in your user name (userid) and password to log in, the system encrypts your password and compares it against the encrypted password in the password files. If they match, you are allowed to log in. At log-in time, the system sets your current directory to be the HOME directory listed for your account in the password file. An initial environment is prepared (e.g. containing a system default PATH). For a text command-line (terminal or console) log in, the shell specified in the password file is executed. (This shell is usually /bin/bash.) For a graphical log-in, a window manager is started and your Desktop is initialized for display. If your login shell is /bin/bash, the bash process reads ("sources") some system start-up files such as /etc/profile and /etc/bash.bashrc that may set system defaults for various Environment Variables. Next, a login shell looks in your home directory for more start-up files such as .bash_profile and .bash_login that you can use to alter the system defaults. (See "man bash" for the full list.) You can create your own initialization files to customize your environment and terminal settings. (Some systems give default .bash_login and .bash_logout files when you create a new account. The default files are copied from a system directory such as /etc/skel.) -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/