Ubuntu – Execute a Command Every Time Terminal Is Open

terminalUbuntu

I'm on Ubuntu 13.04 and I'd like to configure my terminal, so that every time a new tab/window is open, it executes the following command automatically and right away.

 /bin/bash --login

How could I achieve this? On OSX with iTerm 2 there is an option to run a command on start. I guess here I should achieve this thru some kind of dotfile…

Best Answer

Add the command to your ~/.bashrc. Technically, you should be able to add to ~/.profile as well, from man bash, INVOCATION documentation:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.

Also:

Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc and ~/.bashrc, if these files exist and are readable.

So, this means that if you're logged in locally you should be OK using ~/.profile; but, if you ssh to systems then you'll want to use ~/.bashrc. ~/.bashrc also applies when logged in locally; so, it has just become convention to use that.

Related Question