Changing PATH in .profile doesn't affect bash login shell

Asked by Ken Turkowski on 2011-11-21

I made my own bin directory, and edited my .profile to include this directory. When I exit the Terminal and start it up again, my path has not been updated. Neither .bash_profile nor .bash_login exists. I can execute ". .profile" and the PATH is updated.

Why is my .profile ignored on Ubuntu 11.10? I tried moving .profile to .bash_profile, with the same results. The documentation says this should work, just like on other Unices.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
2011-11-21
Last query:
2011-11-21
Last reply:
2011-11-21

Did you log out and back in?

If so, and it still doesn't work, then please provide the output of:

echo $PATH; echo; ls -ld .*; echo; cat ~/.profile

Ken Turkowski (turk) said : #2

turk@Cumulus-ubuntu:~$ floatval -x 3f800000
floatval: command not found
turk@Cumulus-ubuntu:~$ . .profile
turk@Cumulus-ubuntu:~$ floatval -x 3f800000
1 = F(3F800000) = D(3FF00000 00000000)

Ken Turkowski (turk) said : #3

turk@Cumulus-ubuntu:~$ logout
bash: logout: not login shell: use `exit'

What the?????? Why would Terminal start me up with a shell that is not a login shell?

Why *would* the Terminal start you with a login shell? The act of opening the Terminal does not involve logging in...

If you were to press Ctrl+Alt+F1 (or ...+F2 or ...+F3 and so forth) and log in, or if you were to SSH in to your machine, *then* you would get a login shell. A login shell is intended to be the first program run from logging in, such that you are automatically logged out when that program quits. When you log in graphically, that program is not bash, and a bash shell started in a subsequently launched Terminal window is not a login shell.

Try logging out (right click the power/configuration icon at the upper-right corner of the screen and click Log Out) and back in, open a Terminal, and see if your PATH is the way you want it. (Rebooting instead of logging out also works.)

Ken Turkowski (turk) said : #5

[blush] Previously, I only closed the Terminal window, and reopened a new one.
       When I tried completely logging out and logging in again it does work.
       THANK YOU, ELIAH!
       I feel like such a newbie.

But this is not what I would expect, or at least this is not the behavior that I experience on MacOS X. There, I can tweak a .profile and test it by just opening a new window.

Years ago, I made buggy changes to my .profile that prevented me from opening a new window. Luckily, I still had a terminal window open, so I could fix the bug. In the current behavior on Ubuntu, it seems that I need to completely log out to test the .profile. If I did make a bad edit, though, I would be completely hosed, especially if there were no other administrator accounts! How would I develop new additions to my .profile in this situation? Would I need to ssh in from another machine and keep the login window open? Is there a single-machine method that I could use to debug a .profile?

Ken Turkowski (turk) said : #6

Good point, Eliah, about the login shell. Sorry for the naïve question.

Ken Turkowski (turk) said : #7

Thanks Eliah Kagan, that solved my question.

"But this is not what I would expect, or at least this is not the behavior that I experience on MacOS X. There, I can tweak a .profile and test it by just opening a new window."

Yes, I think that in Terminal.app on Mac OS X, bash is invoked as though it is a login shell (probably using method 1 below).

"Is there a single-machine method that I could use to debug a .profile?"

Yes, there are a few ways:

(1) Run "bash -l". (Without the quotes, and -l is lower-case -L, not upper-case -i.) That makes bash act as though it was invoked as a login shell, whether or not it actually was.

(2) This is really just a variation on way 1, but you could create a custom Terminal profile that, when used, uses "bash -l" as the shell instead of "bash".

(3) Log in nongraphically on a virtual terminal as described in my previous post.

Since only method 3 really gives you a login shell, it's the only way to be sure of the change. But when the change is something simple like changing an environment variable (as in this case), any of the methods should be sufficient.