title: How does this script for naming iTerm tabs work?
body: <p>I'm trying to name my iTerm tabs and found <a href="http://blog.locut.us/2009/10/30/simple-bash-script-to-name-a-tab-in-iterm/" rel="nofollow">this link.</a> Here is the pertinent part of the guy's post:</p>
  
  <blockquote>
    <p>I wrote a simple script, which I call “nametab”, which allows you to name the tab you are in from the command line. You just type something like:</p>
  
  <pre><code>$ nametab New tab name
  </code></pre>
    
    <p>If you’d like to use this yourself, here is the code:</p>
  
  <pre><code>#!/bin/bash
  
  # A simple script which will name a tab in iTerm
  # usage:
  # $ nametab New tab name
  
  echo -ne "\033]0;"$@"\007"
  </code></pre>
  </blockquote>
  
  <p>I have created a directory <code>$HOME/dev/bash_scripts</code> and placed a file in that directory called <code>nametab.sh</code>.  I then switched to that directory and ran the command</p>
  
  <pre><code>chmod u+x nametab.sh
  </code></pre>
  
  <p>But when I try to name my current tab in iTerm by typing <code>nametab.sh New tab hellooooo</code>, nothing happens.  I also tried <code>nametab.sh hellooooo</code>, and nothing happens.</p>
  
  <p>Can you help me understand what I don't understand?</p>
  
  <hr>
  
  <h2>Update:</h2>
  
  <pre><code>echo TERM=$TERM
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>TERM=xterm-256color
  </code></pre>
  
  <p>and</p>
  
  <pre><code>echo $PATH
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>.:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/dev/bash_scripts
  </code></pre>
  
  <p>and</p>
  
  <pre><code>cat ~/dev/bash_scripts/nametab.sh
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>#!/bin/bash
  
  # A simple script which will name a tab in iTerm
  # usage:
  # $ nametab NewTabName
  
  echo "trying to rename the current tab to $@"
  echo -ne "\033]0;"$@"\007"
  echo "finished"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>nametab.sh hellooooo
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>trying to rename the current tab to helloooo
  finished
  </code></pre>
  
  <p>but the tab name always stays the same.</p>
  
  <p>Incidentally, the tab name reads</p>
  
  <pre><code>MindRoot (bash)
  </code></pre>
  
  <p>I am running iTerm2.  I try to do all my bash shell configuration in <code>/etc/bashrc</code>.  This way I get the same bash terminal behavior regardless of which user account I am logged in on.  The contents of <code>/etc/bashrc</code> is</p>
  
  <pre><code># System-wide .bashrc file for interactive bash(1) shells.
  if [ -z "$PS1" ]; then
     return
  fi
  
  #PS1='\h:\W \u\$ '
  # Make bash check its window size after a process completes
  shopt -s checkwinsize
  
  # ALL OF THE BELOW ADDED BY DEONOMO ON 2011-04-25
  
  # custom prompt
  PROMPT_HOSTNAME='MindRoot' 
  PROMPT_COLOR='0;35m'
  
  # If I am root, set the prompt to bright red
  if [ ${UID} -eq 0 ]; then
  PROMPT_COLOR='1;31m'
  fi
  
  PS1='\[\e]1;${PROMPT_HOSTNAME}\a\e]2;${PROMPT_HOSTNAME}:${PWD}\a\
  \e[${PROMPT_COLOR}\]\
  [\u@${PROMPT_HOSTNAME} \w]\n \#\$ \
  \[\e[m\]'
  
  #PS1="\e[0;45m\w:$ "
  
  # added by Deonomo on 2011/09/12 in order to have textmate work as default editor
  export EDITOR='mate -w'
  
  # added by Deonomo on 2012-01-11 in order to start a dev/bash_scripts directory
  export PATH="$PATH:~/dev/bash_scripts"
  </code></pre>