Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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'm trying to launch one command in a new gnome-terminal window from a shell script, and it seems that my .bashrc file doesn't get sourced when calling gnome-terminal and executing a command:

gnome-terminal -t "my title" -e vim

But it does when launching gnome-terminal alone:

gnome-terminal -t "my title"

(for testing purposes, just add a echo "something" to the end of the .bashrc)

I also tried explicitly sourcing the .bashrc before running vim with no success:

gnome-terminal -t "my title" -x $SHELL -c "source $HOME/.bashrc; vim"

Am I missing something?

share|improve this question

No, your are correct. gnome-terminal does not source .bashrc when running a command via the -e argument.

Bash and gnome-terminal are two separate things. When you run without -e gnome-terminal runs your default shell (which happens to be bash). When you run with -e gnome-terminal runs the command you provided (bash is not loaded so .bashrc is not sourced).

Your last example will not work either. $HOME is a variable in bash and not available. In addition source is a bash command, and vim likely needs a path.

The best way to do this, in my opinion is to make a wrapper script.

In your path somewhere (I added ~/.bin/ to my path) create a file called vim-x and set it executable.

source $HOME/.bashrc
vim "$@"

Then you can run:

gnome-terminal -t "my title" -e /home/user/.bin/vim-x

share|improve this answer
Thanks for your reply. I tried this approach and it still doesn't work (no echo "something" in the new gnome-terminal window) – el.atomo Nov 21 '12 at 13:10
up vote 2 down vote accepted

I found the problem with the help of this reply.

Actually the .bashrc was sourced, but not completely processed because of the following lines:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

To bypass the problem, the cleanest approach would be to force the shell instance to be run in interactive mode (as seen here):

gnome-terminal -t "my title" -x $SHELL -ic "vim"
share|improve this answer
careful that will break things user wide. – coteyr Nov 21 '12 at 13:45
Thanks @coteyr. I've updated my answer. – el.atomo Nov 21 '12 at 14:05
Glad you got it working. – coteyr Nov 21 '12 at 14:10

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.