4 Answers
4

The .profile was the original profile configuration for the Bourne shell (a.k.a., sh). 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.

If i am wrong, do correct me.. .profile is used by any Bourne compatible shell whereas .bash_profile is used by bash only.. am i right?
–
lakeshAug 17 '12 at 5:08

1

@lakesh: Yes, any shell providing bourne compatibility will read .profile. E.g., bash and ksh but not csh or tcsh. And zsh provides both sh and csh compatibility so it will read both .profile and .login, as well as zsh specific dot files.
–
bahamatAug 17 '12 at 7:59

is there any tutorial to read up on this bash and ksh stuff? never heard of these before...
–
lakeshAug 17 '12 at 8:02

A login shell is simply a shell you can login as via it ssh or at the console. A non-login shell is a shell that someone can not login too. A non-login shell is often used by programs/system services.

As for your third point. It is true .bashrc is executed on each instance of the shell. However .bash_profile is only used upon login. Thus the reason for the two separate files.

.profile is for things that are not specifically related to Bash, like environment variables $PATH it should also be available anytime. .bash_profile is specifically for login shells or shells executed at login.

.profile is for things that are not specifically related to Bash, like environment variables PATH it should also be available anytime. .bash_profile is specifically for login shells or shells executed at login.
–
anzenkethAug 17 '12 at 4:54

When you you login in UNIX machine redirect to your home directory, According to your shell that administrator chose for you in last field of /etc/passwd such as :

mohsen:x:1000:1000:Mohsen Pahlevanzadeh,,,:/home/mohsen:/bin/bash

Your shell will be run and behave for you, By default each has a set file for login and logout when you login in bash shell , ~/.profile is run and when you logout , ~/.bash_logout is run.
~/.bash_history file keeps your input command.

Initialization file in each shell

TENEX C SHELL:

~/.login = > When you login
~/.logout = > When you logout
~/.tcshrc = > same as ~./bashrc in bash shell
You can set variable $histfile as name of history file and variable $history as number of commands to keeping.

Z SHELL

Indeed it's powerful shell and if i get free time, be sure migrate to it.

Except of other shell, Z shell has many configuration file and initialization files, just i write: