 |
 |
.bashrc not sourcing
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
On a default install of OS X Panther, I created a .bashrc to alias a few commands. It is not sourcing. If I type "source .bashrc" the alias works properly, but when I open Terminal, or SSH into the machine it doesn't source. If I type "bash" to execute a new instance of the shell, .bashrc sources properly. But just opening a new Terminal window or logging into the machine does not do it properly.
Any thoughts? I thought I read about this at one point but I cannot find the thread.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by Xeo:
On a default install of OS X Panther, I created a .bashrc to alias a few commands. It is not sourcing. If I type "source .bashrc" the alias works properly, but when I open Terminal, or SSH into the machine it doesn't source. If I type "bash" to execute a new instance of the shell, .bashrc sources properly. But just opening a new Terminal window or logging into the machine does not do it properly.
Any thoughts? I thought I read about this at one point but I cannot find the thread.
I don't have Panther here yet so I can't test this... but take a look at your ~/.bash_profile if you have one. Mine looks like this:
Code:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
You also might want to type in env and check to see what your shell is set to. It may still be tcsh. Not sure where you set that in Panther.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Originally posted by utidjian:
You also might want to type in env and check to see what your shell is set to. It may still be tcsh. Not sure where you set that in Panther.
Yep, the shell is definitely bash. I don't know why .bashrc isn't being sourced 'cause the bash manpage says it should. However, I created a .bash_profile and put your code into it. It worked, so thanks for that. I just decided to put the contents of .bashrc into .bash_profile instead, since that seemed to get sourced properly. I don't care what the file is called, and I only have a few aliases to set up, so one file will do.
Thanks again.
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Ya know, I think I finally understand the man page on this issue. You'd think I could read better the first time, but maybe I've had more sleep and my mind is working properly now. I dunno.
Anyway, it seems ~/.bashrc is purposely not sourced when an interactive login shell is started. So basically, when you create a new terminal window or log in via SSH, it isn't supposed to source. However, when you just type "bash" you are starting a new interactive shell that is NOT a login shell, and ~/.bashrc does get sourced. ~/.bash_profile seems to get sourced at the start of a new interactive login shell, but NOT sourced when it is not a login shell. Which means typing "bash" will result in all your aliases in .bash_profile from being sourced. So, using utidjian's method will result in always getting your aliases no matter how you start an interactive shell.
Please correct me if I'm wrong, but I think I got it. 
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by Xeo:
Ya know, I think I finally understand the man page on this issue. You'd think I could read better the first time, but maybe I've had more sleep and my mind is working properly now. I dunno.
Anyway, it seems ~/.bashrc is purposely not sourced when an interactive login shell is started. So basically, when you create a new terminal window or log in via SSH, it isn't supposed to source. However, when you just type "bash" you are starting a new interactive shell that is NOT a login shell, and ~/.bashrc does get sourced. ~/.bash_profile seems to get sourced at the start of a new interactive login shell, but NOT sourced when it is not a login shell. Which means typing "bash" will result in all your aliases in .bash_profile from being sourced. So, using utidjian's method will result in always getting your aliases no matter how you start an interactive shell.
Please correct me if I'm wrong, but I think I got it.
I think you have it exactly right!... But... not sure how to parse this sentence:
"Which means typing "bash" will result in all your aliases in .bash_profile from being sourced."
Did you mean:
Which means typing "bash" will result in all your aliases in .bash_profile being sourced.
?
Anyhow... for a terse but unambiguous description of bash startup files and just about everything bash try:
info bash
Which will start up the emacs info page on bash. This can be awkward to use if you are not familiar with emacs. To quit the info page at any time type Ctrl-X Ctrl-C.
The part that describes how the startup files are used is under
* Bash Features::
then
* Bash Startup Files::
(use the arrow keys until the cursor is on those lines and press Enter).
What would be cool is if Safari had a feature like Konqueror where one can type "info:bash" in the URL line and it pulls up the same document but with hyperlinks and a much more familiar interface.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Xeo-
.bash_profile is read when you log into the Terminal. If you make changes to it, you need to either exit and create a new session to use the changes or enter source .bash_profile which will execute the commands in .bash_profile.
If you start a child shell by typing bash at the command line, .bashrc is read. This allows separate startup commands for the original interactive shell and subsequent child (sub) interactive shells.
In my .bash_profile I have :
Code:
. ~/.bashrc
ENV=$HOME/.bashrc
export ENV
This way I make a choice to access the same command set for both the parent shell and any subsequent sub-shells. .bash_profile calls .bashrc and then sets ENV as an environment variable with the export command.
The read order is .bash_profile, .bashrc, .bash_logout. .bash_login and .profile are synonyms for .bash_profile.
HTH
Craig
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|