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 6673357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:37:06+00:00 2026-05-26T03:37:06+00:00

Can anyone help explain what’s going on with tmux , bash , and exec

  • 0

Can anyone help explain what’s going on with tmux, bash, and exec? I’m trying to set up a tmux session with a 4-pane window. Ideally, I want to run a command in 3 of the panes: e.g. a Ruby Thin server and a couple of Ruby daemons. This is what I have so far:

~/.bin/tmux-foo:

#!/bin/sh

tmux new-session -d -s foo 'exec pfoo "bundle exec thin start"'
tmux rename-window 'Foo'
tmux select-window -t foo:0
tmux split-window -h 'exec pfoo "bundle exec compass watch"'
tmux split-window -v -t 0 'exec pfoo "rake ts:start"'
tmux split-window -v -t 1 'exec pfoo'
tmux -2 attach-session -t foo

~/.bin/pfoo:

#!/bin/bash
cd ~/projects/foo
rvm use ree

# here I want to execute command1 2 3 or 4...

exec $SHELL

It all works… but when I ctlr-c in the first pane that is running the thin server, it stops the thin server and returns to the shell. However, the command is not in the history; i.e. if I hit the up key I don’t get the bundle exec thin start command… I get some other command from my bash history. I’m wondering if there’s any way to arrange these scripts so that I get the commands in the bash history.

Also… I’ve tried many combinations of exec, exec $SHELL -s ..., and exec $SHELL -s ... -I and I’m not quite sure what is going on…

Can anyone help explain the general idea of what is going on with tmux and bash and exec here?

  • 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-26T03:37:06+00:00Added an answer on May 26, 2026 at 3:37 am

    As others have mentioned, your commands are being run by the shell script before launching your $SHELL; there is no general way the instance of $SHELL can know what its parent ran before starting it.

    To get the “initial command” into the shell history, you need to feed the command keystrokes directly to the instance of $SHELL itself (after it has been started, of course). In other contexts I might suggest using a small Expect program to spawn an instance of $SHELL, feed it the keystrokes, then use interact to tie the tty to the expect-spawned $SHELL.

    But in the context of tmux, we can just use send-keys:

    #!/bin/sh
    
    tmux new-session -d -s foo 'exec pfoo'
    tmux send-keys 'bundle exec thin start' 'C-m'
    tmux rename-window 'Foo'
    tmux select-window -t foo:0
    tmux split-window -h 'exec pfoo'
    tmux send-keys 'bundle exec compass watch' 'C-m'
    tmux split-window -v -t 0 'exec pfoo'
    tmux send-keys 'rake ts:start' 'C-m'
    tmux split-window -v -t 1 'exec pfoo'
    tmux -2 attach-session -t foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me with the trying to write SQL (MS SqlServer) - I
can anyone help me in trying to check whether JavaScript is enabled in client
Can anyone help? I have been using the entity framework and its going well
Can anyone help me explain how TimeProvider.Current can become null in the following class?
Can anyone help explain the following. I am having an issue with a Dictionary
Can anyone help explain this? I am using the Populator and Faker gems to
Help, can anyone help out and explain the purpose of the Rhino Mocks 'Record'
Can anyone help explain why JNDI should be a preferred way to expose services
Can anyone help explain to me why the following is returning duplicate data? <?php
Can anyone help explain why the code below fails to retrieve the html Dim

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.