title: Shell script: setting title for new gnome-terminal tab
body: <p>I try to automate the setup of my environment. Doing this I need to open several tabs in a terminal and execute commands. The tabs should have a title to distinguish them. The script should only write the commands in the tabs without executing.</p>
  
  <p>The script expects an input file start.txt. This one will be processed line by line - each line contains first the title for the terminal tab and separated with a comma the command.</p>
  
  <p>With a very easy gnome-terminal call the title will be shown:</p>
  
  <blockquote>
    <p>gnome-terminal -- tab --title=test1 -e top --tab --title=test2 top</p>
  </blockquote>
  
  <p>But when taking a complex command this won't work and the title will not be set.</p>
  
  <p>Here is the whole code:</p>
  
  <pre><code>#!/bin/bash
  
  # define variable which needs to be executed
  cmdline="gnome-terminal"
  # define input file
  file="cat start.txt"
  # define run_command script
  destdir=/home/ank1abt/Documents/run_command.sh
  
  
  # create if not already existing and change permissions
  touch $destdir
  chmod 755 $destdir
  
  # read file an process line by line 
  # each line contains first the title and with comma separated the command for a new tab in a terminal
  $file | \
  while read row; do
    #extract tab title and command   
    title=$(echo $row | awk -F","  '{print $1}')
    cmd=$(echo $row | awk -F","  '{print $2}')  
    set_title="export PS1='\[\e]0;"$title"\a\]\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\$'"      
    #cmdline=$cmdline\ "--tab --title="$title" -e top"
    cmdline=$cmdline\ "--tab --title="$title" -e \"bash -c \\\" echo "$title"; echo export PS1='\[\e]0;"$title"\a\]\\\${debian_chroot:+(\\\$debian_chroot)}\u@\h:\w\$';echo "$cmd"; exec bash\\\"\""
    echo $cmdline   
    # command will be written to a file
    echo "$cmdline" &gt; $destdir
  done
  
  # execute the file with the command
  exec "./run_command.sh"
  </code></pre>
  
  <p>In the meantime I tried a workaround. There is another interesting command with which you could set the tab title from within the tab which could then be executed in the tab or just written there so that the user can copy and execute it:</p>
  
  <blockquote>
    <p>export
    PS1='[\e]0;mission\a]${debian_chroot:+($debian_chroot)}\u@\h:\w$'</p>
  </blockquote>
  
  <p>But with the current code the following command will be written to the run_command script:</p>
  
  <blockquote>
    <p>gnome-terminal --tab --title=test1 -e "bash -c \" echo test1; echo
    export
    PS1='[\e]0;test1\a]\${debian_chroot:+(\$debian_chroot)}\u@\h:\w$';
    echo top; exec bash\"" --tab --title=test2 -e "bash -c \" echo test2;
    echo export
    PS1='[\e]0;test2\a]\${debian_chroot:+(\$debian_chroot)}\u@\h:\w$';
    echo top; exec bash\""</p>
  </blockquote>
  
  <p>When you just copy this command and execute it in a terminal the tabs will show the export command but not enclosed in single quotes and then it won't work.</p>
  
  <blockquote>
    <p>export
    PS1=[\e]0;mission\a]${debian_chroot:+($debian_chroot)}\u@\h:\w$</p>
  </blockquote>
  
  <p>For sure I prefer to get the title option of the gnome-terminal command working but if this won't be possible I would be happy about any hints how to have the values for the export of PS1 in the tabs in singe quotes. I already tried to escape it with \ or several\ without success.</p>