Server Fault is a question and answer site for system and network administrators. 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 sure this shouldn't be as hard as I'm finding it!

When I log into my machine, i want it to start up a bash shell, in a given directory, open and name some tabs, and start a process in each one.

I think that if i put

cd ~/xxx/xxx/xxx

in .bashrc and then autostart the bash shell with something like

gnome-terminal --tab -e "bash -c 'rails s'" --tab -e "bash -c 'spork'" --tab -e "bash -c 'autotest'" --tab -e "bash -c 'rails c'" --tab -e 'tail -f log/development.log'

it should work

It doesn't - I get "There was an error creating the child process for this terminal Failed to execute child process 'rails' (No such file ...

rails is in the path - both in the root and the destination directories, and giving the full path doesn't help - the terminal window doesn't open.

Update: The reason this doesn't work as expected is that bashrc does not change the working directory until the commands to start the process have been executed. (i can see this if i do tab -e 'pwd')

So the question is really, how can I change directory and then start the processes running?

share|improve this question
Is rails in your path when this script executes? Do you need to give the full path to it? – Jez Jul 19 '11 at 9:14
thanx jez - updated the question – chrispanda Jul 19 '11 at 10:12
up vote 3 down vote accepted

There is a very good solution at:

Quoted from link:

Here is a nice trick we worked out at Superuser

  1. Add a eval "$BASH_POST_RC" to the end of your .bashrc

  2. Set the BASH_POST_RC environment variable for each tab to that command you like to execute, e.g.: gnome-terminal --working-directory="/home/zardoz/projects/my_rails_app" --tab -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab -e 'bash -c "export BASH_POST_RC=\"autotest\"; exec bash"'

@Gilles: Thanks for that solution!

I created the following bash script using this idea.

gnome-terminal --working-directory="/home/USER/rails_projects/PROJECT" --tab --title=Terminal --profile=Rails --tab --profile=Rails --title=Console -e 'bash -c "export BASH_POST_RC=\"rails console\"; exec bash"' --tab --profile=Rails --title=Guard -e 'bash -c "export BASH_POST_RC=\"guard\"; exec bash"' --tab --profile=Rails --title=Server -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab --profile=Rails --title=Tail -e 'bash -c "export BASH_POST_RC=\"tail -f log/development.log\"; exec bash"'

share|improve this answer

.bashrc isn't invoked when bash called with -c parameter.

Instead you could wrap calling gnome-terminal in script which does cd first. Some like this:

cd ~/xxx/xxx/xxx
gnome-terminal --tab -e "bash -c 'rails s'" --tab -e "bash -c 'spork'" --tab -e "bash -c 'autotest'" --tab -e "bash -c 'rails c'" --tab -e 'tail -f log/development.log'
share|improve this answer
nice simple solution - thanks. – chrispanda Jul 19 '11 at 10:53

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.