Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6978649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:47:02+00:00 2026-05-27T17:47:02+00:00

I want to use a script to open a tmux session with 6 windows,

  • 0

I want to use a script to open a tmux session with 6 windows, each in a different directory. I started with a script I found and tried this first:

tmux new-session -s xyz   -n etc -d 'cd /etc'
tmux new-window  -t xyz:1 -n var    'cd /var/log'

But I soon found out that this will not work as I expected — the window will be closed after the shell command completes.

So my next idea was to start a new shell like this:

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

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:

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

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:47:03+00:00Added an answer on May 27, 2026 at 5:47 pm

    The shell errors are probably due to some problem in your startup files (or something they run).

    As shellter commented, temporarily including the command set -vx early in your startup sequence is a good way to find out where the errors are occurring.
    If you find the -vx output too verbose, you could try “printf debugging” (manually adding debug statements to your startup files until you can narrow down exactly which lines are causing the errors):

    • Put echo start of .bashrc and echo end of .bashrc at the start/end of your .bashrc to see if the error occurs during your .bashrc. If not, instrument your other startup files: .bash_profile/.bash_login/.profile. If the errors happen before that file, then the problem may be in /etc/profile.
    • Once you know which file is being processed when the errors occur, add more debug outputs around each “major block” or line to narrow down the responsible section/line.
    • The errors may not actually be in your startup file itself, but in a script that it runs.

    Note: These debug additions need to be temporary since they will cause problems if you ever use a program that makes automated logins (e.g. rsync, SSH-based Git access, etc.) since these programs expect a “clean” connection without such debugging noise present.


    There should be no need to use cd command like that in the shell-command argument given to either tmux new-session or tmux new-window.

    A new window will “inherit”† the current working directory when using new-session and new-window from the command line (i.e. when done through the tmux binary, instead of via a binding or at a tmux–: prompt). According to the CHANGES file, it looks like this has been the case since tmux 0.6 (at least for new-window).

    † This is tmux-mediated inheritance, not the parent–child inheritance that is the usual mechanism for passing along the cwd.

    This script works for me with tmux 1.5:

    #!/bin/bash
    # var for session name (to avoid repeated occurences)
    sn=xyz
    
    # Start the session and window 0 in /etc
    #   This will also be the default cwd for new windows created
    #   via a binding unless overridden with default-path.
    cd /etc
    tmux new-session -s "$sn" -n etc -d
    
    # Create a bunch of windows in /var/log
    cd /var/log
    for i in {1..6}; do
        tmux new-window -t "$sn:$i" -n "var$i"
    done
    
    # Set the default cwd for new windows (optional, otherwise defaults to session cwd)
    #tmux set-option default-path /
    
    # Select window #1 and attach to the session
    tmux select-window -t "$sn:1"
    tmux -2 attach-session -t "$sn"
    

    This might also (as a side-effect) alleviate your shell startup errors since the way tmux starts a shell is different from a plain bash -i (it is more akin to bash -l, which uses your .bash_profile/.bash_login/.profile instead of (just) your .bashrc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute a php-script from php that will use different constants and
There's this line I want to use in a ksh script : find .
I want to use the same ant script to do a build in either
I want to execute a script every 30mins, but i want to use it
I want to use the <nant> task in my build script but I want
I have a contact form i want to use Ajax for. My contact.php script
I use such script to open pop-ups : <script> var wins = []; openWin
I want to use response.redirect to open page in new window or tab. I
I nside a html.erb, I want to use the logger <script type=text/javascript> $j(function(){ $j('#AddQuestion').click(function(){
Every second this script will open a page using AJAX and return the contents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.