I want to be able to name a terminal tab so I can keep track of which one is which. I found this function (here) and put it in my .bashrc:

function set-title() {
  if [[ -z "$ORIG" ]]; then

and now when I call set-title my new tab name the tab name is changed as expected to "my new tab name". The problem is that I want to open a new tab and name it using set-title. The way I have tried to do this, is like this:

gnome-terminal --geometry=261x25-0+0 --tab -e "bash -c 'set-title tab1; sleep 10'" --tab -e "bash -c 'set-title tab2; sleep 10"

However, now I get the following error message:

bash: set-title: command not found

And I think this is to do with the new gnome tab not knowing about the .bashrc function yet.

How can I get this to work?

  • 1
    For non-interactive use, why involve the $PS1 hack? Just echo the magic string that sets the title.
    – Celada
    Nov 3, 2016 at 8:32
  • So, just replace PS1= with echo?
    – Haych
    Nov 3, 2016 at 10:03
  • @Haych: check my answer Nov 3, 2016 at 11:41

2 Answers 2


Instant of using function set-title you can create command with this functionality, so remove function set-title() that you add from ~/.bashrc and create a file /usr/local/bin/set-title:

echo -ne "\033]0;$1\007"

Add chmod: chmod +x /usr/local/bin/set-title. And after you re-open terminal you can use this command by: set-title TEST (If you have /usr/local/bin/ in your $PATH).

And then you can use it when creating new tab by this way:

gnome-terminal --geometry=261x25-0+0 \
    --tab -e "bash -c 'set-title TAB1; sleep 10'" \
    --tab -e "bash -c 'set-title TAB2; sleep 10'"

If you somehow don't have /usr/local/bin/ in your $PATH, you can try with absolute path to the set-title command:

--tab -e "bash -c '/usr/local/bin/set-title TAB1; sleep 10'"
  • This didn't work for me. The function I am using actually puts text in the tab so then i can know which is which. This didn't do that for me unfortunately!
    – Haych
    Nov 3, 2016 at 12:44
  • But my solution works, and puts text in title. When I run above command, I get: i.imgur.com/587bmcG.png If you don't have this results you makes something wrong, you have some error? Nov 3, 2016 at 13:18

If you want your .bashrc, .bash_profile, .profile, etc initialization scripts run, start gnome-terminal with --login option.


You must log in to answer this question.

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