On 28/06/11 7:44 AM, J Irving wrote:
Hi

I just switched to bash, having been using zsh for a few years, and I
notice that when I start MacVim using the mvim script, my
~/.bash_profile file is sourced. I'm pretty sure this file should only
be sourced if bash is started interactively, which is not the case
here. Anyone know why this is happening? And ideally how to prevent
it?

Bash's startup behaviour is pretty braindead, IMHO.

~/.profile or ~/.bash_profile is sourced for a login shell.

~/.bashrc is sourced for an interactive non-login shell.

Except for ssh logins, ~/.bashrc is sourced even in the non-interactive
case, and even though it's a login (so the exact opposite of what
~/.bashrc is usually for).

A non-interactive non-login shell has nothing sourced (except for some
script that can be named in an environment variable).

MacVim starts a login shell when it spawns Vim processes, because that's
what most users expect, and what Terminal.app does when you open a new
window. The shell MacVim spawns is non-interactive, though, not
interactive, of course. However, it results in ~/.profile or
~/.bash_profile being sourced.

What a lot of people do is have ~/.profile or ~/.bash_profile do things
they want in all login shells, and have that *also* source ~/.bashrc to
do things they want only in interactive shells. Something like this:

if echo $- | grep -q i ; then
  [ -r ~/.bashrc ] && source ~/.bashrc
fi

Getting ssh logins to do something sane is another nightmare. I have
code for that if anyone is interested, as well as more extensive code to
integrate the same kind of behaviour system-wide using /etc/profile and
so on. Just let me know if you want a copy and I will gather it together
and send.

Hope this helps!

Ben.



--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to