bash_profile question
ZIYAD A. M. AL-BATLY
zamb at spymac.com
Mon Apr 4 22:04:24 UTC 2005
On Mon, 2005-04-04 at 16:40 -0400, Paul Pianta wrote:
> Hi
>
> My default ~/.bash_profile has the following in it ...
>
> # set PATH so it includes user's private bin if it exists
> if [ -d ~/bin ] ; then
> PATH=~/bin:"${PATH}"
> fi
>
> and I have created a 'bin' directory in my home ...
>
> pantz at faramir:~$ ll ~/
> total 12
> drwxr-xr-x 2 pantz pantz 4096 2005-04-04 15:02 bin
> drwxr-xr-x 2 pantz pantz 4096 2005-04-03 22:13 Desktop
> drwxr-xr-x 2 pantz pantz 4096 2005-03-11 17:56 Templates
>
>
> Can someone tell me why when I echo $PATH my home 'bin' dir doesn't show
> up (p.s. - ignore the /home/pantz/.local/bin - it is there because of an
> 'autopackage' test)
>
> pantz at faramir:~$ echo $PATH
> /home/pantz/.local/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games
>
> but then I do this ...
>
> pantz at faramir:~$ PATH=~/bin:"${PATH}"
> pantz at faramir:~$ echo $PATH
> /home/pantz/bin:/home/pantz/.local/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games
>
> or this ...
>
> pantz at faramir:~$ . .bash_profile
> pantz at faramir:~$ echo $PATH
> /home/pantz/bin:/home/pantz/.local/bin:/home/pantz/.local/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games
>
> and it is all ok with /home/pantz/bin showing up first.
>
> My question is - why is my bash_profile not being automatically sourced
> each time I open a new terminal?
>
> thanks
>
> pantz
>
~/.bash_profile is read and executed for *login* shells only!.
If you want to change $PATH, either pass the --login option to the shell
(or configure your preferred terminal-emulation application to do that
for you each time (in gnome-terminal: start a terminal and right-click
anywhere in it and choose "Edit Current Profile..." then go to "Title
and Command" tab and check "Run command as a login shell")) or put your
change(s) in ~/.bashrc instead (it will be read and executed for
interactive non-login shell).
Quote from the bash manual:
* When bash is invoked as an interactive login shell, or as a
non-interactive shell with the --login option, it first reads
and executes commands from the file /etc/profile, if that
file exists. After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile, in that order,
and reads and executes commands from the first one that exists
and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
* When a login shell exits, bash reads and executes commands from
the file ~/.bash_logout, if it exists.
* When an interactive shell that is not a login shell is started,
bash reads and executes commands from /etc/bash.bashrc and
~/.bashrc, if these files exist. This may be inhibited by using
the --norc option. The --rcfile file option will force bash to
read and execute commands from file instead
of /etc/bash.bashrc and ~/.bashrc.
* When bash is started non-interactively, to run a shell script,
for example, it looks for the variable BASH_ENV in the
environment, expands its value if it appears there, and uses the
expanded value as the name of a file to read and execute. Bash
behaves as if the following command were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the
file name.
* If bash is invoked with the name sh, it tries to mimic the
startup behavior of historical versions of sh as closely as
possible, while conforming to the POSIX standard as well. When
invoked as an interactive login shell, or a non-interactive
shell with the --login option, it first attempts to read and
execute commands from /etc/profile and ~/.profile, in that
order. The --noprofile option may be used to inhibit this
behavior. When invoked as an interactive shell with the name
sh, bash looks for the variable ENV, expands its value if it is
defined, and uses the expanded value as the name of a file to
read and execute. Since a shell invoked as sh does not attempt
to read and execute commands from any other startup files, the
--rcfile option has no effect. A non-interactive shell invoked
with the name sh does not attempt to read any other startup
files. When invoked as sh, bash enters posix mode after the
startup files are read.
* When bash is started in posix mode, as with the --posix command
line option, it follows the POSIX standard for startup files.
In this mode, inter‐active shells expand the ENV variable and
commands are read and executed from the file whose name is the
expanded value. No other startup files are read.
Ziyad.
More information about the ubuntu-users
mailing list