Link to home
Create AccountLog in
Avatar of @nir
@nirFlag for United States of America

asked on

Tmux in bash script

This bash script  opens 4 windows exactly of same size.

#!/bin/sh
tmux new-session \; \split-window -v \; \split-window -h \; \select-pane -t 0 \; \split-window -h

Open in new window

Is it possible to run some commands  on all 4 panes ?
 some thing like

#!/bin/bash
tmux new-session \; \split-window -v "ls -la" \; \split-window -h "top" \; \select-pane -t 0 \; \split-window -h "cd ~"

Open in new window

Some guidance from tmux and shell script gurus will be highly admired.
:-)

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

A quick look in the man page shows the -c option that may be used:


-c shell-command
Execute shell-command using the default shell.  If necessary, the tmux server will be started to retrieve the default-shell option.  This option is for compatibility with sh(1) when tmux is used as login shell.


I haven't tested this btw. 

ASKER CERTIFIED SOLUTION
Avatar of madunix
madunix

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of @nir

ASKER

Thank you @madunix. with bash-c and exec bash.
I was able to do what was intended.
User generated image

#!/bin/bash
tmux new-session -d 'bash -c "echo Window1; exec bash"'
tmux split-window -v 'bash -c "echo Window2; exec bash"'
tmux split-window -h 'bash -c "echo Window3; exec bash"'
tmux select-pane -t 0
tmux split-window -h 'bash -c "echo Window4; exec bash"'
tmux attach-session

Open in new window