.profile was the original profile configuration for the Bourne shell (a.k.a.,
bash, being a Bourne compatible shell will read and use it. The
.bash_profile on the other hand is only read by
bash. It is intended for commands that are incompatible with the standard Bourne shell.
.profile on startup.
bash will try to source
.bash_profile first, but if that doesn’t exist, it will source
Note that if
bash is started as
/bin/sh is a link to
/bin/bash) or is started with the
--posix flag, it tries to emulate
sh, and only reads
- Actually, the first one of
- Bash Reference Manual – Startup Files
- UNIX sh man page – Invocation
You know many shells exist in the UNIX world, but most of them are:
- Bourne shell:
/bin/sh(Inventor: Stephen Bourne)
- BASH (Bourne Again Shell):
/bin/bash(Inventor: Brian Fox, under GNU project) (powerful shell)
- C shell:
/bin/csh(Inventor: Bill Joy, Inventor of TCP/IP Stack)
- Korn shell:
/bin/ksh(Inventor: David Korn under Bell Labs)
- Z shell:
- TENEX C shell:
/bin/tcsh(derived from C Shell)
- Debian Almquist shell:
/bin/dash(Derived from Almquist shell (ash under NetBSD project)) (Dash born from lenny)
But your question is about
When you you log in to a UNIX machine, it redirects to your home directory, according to the shell chosen by an administrator in the last field of
/etc/passwd such as :
Your shell runs, and by default each shell has a set file for
logout. When you log in on bash,
~/.profile is run and when you
~/.bash_logout is run.
~/.bash_history file keeps your input command.
Initialization file in each shell
TENEX C shell
~/.loginWhen you login
~/.logoutWhen you logout
You can set variable
$histfile as name of history file and variable
$history as number of commands to keeping.
Indeed it’s powerful shell and if you get free time, be sure migrate to it.
Except of other shell, Z shell has many configuration file and initialization files, just i write:
$ZDOTDIR/.zshenv $ZDOTDIR/.zprofile $ZDOTDIR/.zshrc $ZDOTDIR/.zlogin $ZDOTDIR/.zlogout /tmp/zsh* /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin
$ZDOTDIR unset, home set.
Note: TENEX C shell was forked from C shell. C shell supports by BSD.
If you are familiar with C language programing, you should be comfortable since its syntax is similar.
~/.login ~/.cshrc ~/.logout
Note: csh is old. Use tcsh instead.
- rc file: user defined
- logout file: N/A
Bourne Again SHell (BASH)
It’s very very powerful shell and born under GNU project and forked by Bourne Shell.
~/.bash_login ~/.bash_logout ~/.bashrc ~/.bash_profile ~/.bash_history
When you login, bash runs
~/.bashrc isn’t bash initialization file, because bash doesn’t run it.
It dead. Even when you use
man sh, you see manual of
dash. [Editor’s note: the bit about
dash only applies to Debian and Debian-based distros like Ubuntu.]
~/.bash_profile work under bash, but
~/.profile work under Bourne and Korn shell.