Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to write some scripts and have MacVim call some bash commands. I have some aliases and wanted vim to be able to call them, so I knew I needed a login shell, just didn't know how to make vim use one.

I read this: (which didn't work for my MacVim); and this: which seemed like a good idea.

So I opened my .vimrc and put this in: set shell=/bin/bash\ -l.

Now something very strange is happening: I have an alias in my .bash_profile, like so:

alias mytest='echo "TEST!!"'

My .bashrc sources .bash_profile, so I know it shouldn't be a matter of where the alias is set. If I go inside vim and run: :! alias mytest

I see this:

alias mytest='echo "TEST!!"'

Press ENTER or type command to continue

If I run :! mytest, though, this is what I get:

/bin/bash: mytest: command not found

shell returned 127

Press ENTER or type command to continue

So I'm all out of ideas about how this can be happening. How come when I run "alias" the alias is there, but when I run the alias itself, bash doesn't recognize it?

I appreciate any insight anyone can give me on this matter.

Thank you.


I now tried changing my .vimrc line to:

set shell=/bin/bash\ -li

In order to make the shell interactive as well as being a login shell, and it worked.

So I change my question a bit: Why does this make sense? As I understand it, a login shell runs my .bash_profile, and thus loads my aliases. Why is it not sufficient?

share|improve this question
up vote 2 down vote accepted

Aliases are intended as user shorthand, so they only really make sense in interactive shells. Therefore, as the bash man page says: "Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below)." I suppose you could add shopt -s expand_aliases to your .bash_profile, but that might cause unexpected behavior in other sorts of non-interactive shells...

share|improve this answer
Damn, had not gotten to that part of the bash man page. Thanks a lot for your answer! – malvim Apr 7 '11 at 15:46

This should work: :! bash -ic 'mytest; exit'

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.