Open gnome terminal programmatically and execute commands after bashrc was executed

Zardoz picture Zardoz · Oct 9, 2010 · Viewed 7.8k times · Source

I try to build a little script to start my development environment. For that task I try to open a gnome terminal with several tabs where automatically the rails server and autotest is started. But

gnome-terminal --tab -e "rails server" --tab --tab

does not work ("error creating the child process"). Also

gnome-terminal --tab -e "bash -c \"rails server\"" --tab --tab` 

does not work. Any suggestions how to solve that problem?

Answer

Zardoz picture Zardoz · Oct 11, 2010

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!