(dupe note) This is not a dupe of How to set up tmux so that it starts up with specified windows opened?. That question revolves around configuring tmux, and none of the answers there provide an answer to this question. (end note)
Suppose I have two commands
tail -f log1
tail -f log2
How can I programatically call tmux to split a window horizontally and run each of the commands in its own pane, something similar to:
for i in log1 log2; do xterm -e tail -f $i& done
There's no single command to accomplish this; rather, you send multiple commands to the server. This can be done, though, via a single invocation of tmux
.
tmux new-session -d tail -f log1 \; split-window tail -f log2 \; attach
Note that an escaped semicolon is used to separate tmux
commands. Unescaped semicolons are treated as part of the shell command executed by a particular tmux
command.
Adapting the loop in your question might look something like:
tmux_command="new-session -d"
commands=("tail -f log1" "tail -f log2" "tail -f log3")
tmux_command+=" ${commands[0]}"
for cmd in "${commands[@]:1}"; do
tmux_command+="\; split-window $cmd"
done
tmux "$tmux_command \; attach"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With