I have this alias in my .bashrc:

alias s='cd ~/Documents/projects/s && /bin/bash --login && rvm use ruby-1.9'

How can I execute the right part after it enters login shell (/bin/bash --login)?

2 Answers 2


When you run bash --login, this starts a login shell. One of bash's quirks regarding initialization files is that if it is a login shell, it only reads ~/.bash_profile (or if that doesn't exist ~/.bash_login, or if that doesn't exist either ~/.profile), not ~/.bashrc even if the shell is interactive.

To execute code in a login shell, put it in ~/.bash_profile if it's specific to bash, or in ~/.profile if you want it to happen on any log in, even when /bin/sh is invoked.

To make sure that your customizations for interactive shells are applied, put the following code in your ~/.bash_profile:

case $- in
  *i*) if [ -e ~/.bashrc ]; then . ~/.bashrc; fi;;
if [ -e ~/.profile ]; then . ~/.profile; fi

As a refinement of the answer by @Gilles to get ruby to only run when you ask for it, I would edit a copy of your .bashrc file and tell bash to use it with the --rcfile parameter

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .