help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] .bash_profile, .bash_login, and .profile


From: Michael Convey
Subject: [Help-bash] .bash_profile, .bash_login, and .profile
Date: Tue, 7 Jul 2015 19:58:18 -0700

According to the source below,

"bash allows two synonyms for .bash_profile: .bash_login, derived from the
C shell’s file named .login, and .profile, derived from the Bourne shell
and Korn shell files named .profile. Only one of these three is read when
you log in. If .bash_profile doesn’t exist in your home directory, then
bash will look for .bash_login. If that doesn’t exist it will look for
.profile. One advantage of bash’s ability to look for either synonym is
that you can retain your .profile if you have been using the Bourne shell.
If you need to add bash-specific commands, you can put them in
.bash_profile followed by the command source .profile. When you log in, all
the bash-specific commands will be executed, and bash will source .profile,
executing the remaining commands. If you decide to switch to using the
Bourne shell you don’t have to modify your existing files. A similar
approach was intended for .bash_login and the C shell .login, but due to
differences in the basic syntax of the shells, this is not a good idea."

Source: Newham, Cameron (2005-03-29). Learning the bash Shell: Unix Shell
Programming (In a Nutshell (O'Reilly)) (Kindle Locations 2017-2028).
O'Reilly Media. Kindle Edition.

Here are my questions:

Similar to the Bourne shell, can the .profile file be used in combination
with the .bash_profile file to switch between using the bash and Korn
shells?

The author says, "A similar approach was intended for .bash_login and the C
shell .login, but due to differences in the basic syntax of the shells,
this is not a good idea."

If that is the case, what is the purpose of retaining the .bash_login file?

Also, are the following conclusions by Tristram Brelstaff valid?

.bash_login was introduced as part of an unsuccessful attempt at
compatibility with the C shell.  This suggests that its use can be and
should be avoided.  You should never create a .bash_login and if you have
one you should not allow it to be activated (creating a .bash_profile
should ensure this) and should delete it.

.bash_profile is the appropriate place to put bash-specific commands to be
run when starting a login shell.  It would seem sensible to always have a
.bash_profile file and to never allow bash to read .profiledirectly.
Instead the .bash_profile should always end with a command to include the
.profile, but rather than just source .profile it would be better to test
.profile exists first, for example:

if [ -f "$HOME/.profile" ]; then
  source "$HOME/.profile"
fi

Always having a .bash_profile has the additional benefit of preventing any
.bash_login from running.

Source:
http://tristram.squarespace.com/home/2012/7/20/why-profile-bash_profile-and-bash_login.html


reply via email to

[Prev in Thread] Current Thread [Next in Thread]