title: How to start tmux with several windows in different directories?
body: <p>I want to use a script to open a tmux session with 6 windows, each in a different directory. I started with <a href="http://blog.hawkhost.com/2010/07/02/tmux-%E2%80%93-the-terminal-multiplexer-part-2/#tmux-shell-scripting" rel="noreferrer">a script I found</a> and tried this first:</p>
  
  <pre><code>tmux new-session -s xyz   -n etc -d 'cd /etc'
  tmux new-window  -t xyz:1 -n var    'cd /var/log'
  </code></pre>
  
  <p>But I soon found out that this will not work as I expected — the window will be closed after the shell command completes. </p>
  
  <p>So my next idea was to start a new shell like this:</p>
  
  <pre><code>tmux new-session -s xyz   -n etc -d 'cd /etc; bash -i'
  tmux new-window  -t xyz:1 -n var    'cd /var/log; bash -i'
  tmux new-window  -t xyz:2 -n var2   'cd /var/log; bash -i'
  tmux new-window  -t xyz:3 -n var3   'cd /var/log; bash -i'
  tmux new-window  -t xyz:4 -n var4   'cd /var/log; bash -i'
  tmux new-window  -t xyz:5 -n var5   'cd /var/log; bash -i'
  tmux new-window  -t xyz:6 -n var6   'cd /var/log; bash -i'
  
  tmux select-window -t xyz:1
  tmux -2 attach-session -t xyz
  </code></pre>
  
  <p>This almost works. But if I start more than about 4 windows, I frequently see the following bash errors in one of the windows after startup:</p>
  
  <pre><code>bash: [: =: unary operator expected
  bash: [: too many arguments
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: too many arguments
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  bash: [: =: unary operator expected
  </code></pre>
  
  <p>I have no idea why this happens, but I still think that I’m not doing this right. Is there a better way to set up a tmux session over several directories?</p>