Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple tmux bash script not working

Tags:

bash

tmux

I want tmux to open a new window and then cd into a directory, but it doesn't work. It just opens tmux in the directory my script was run from (ie. it doesn't execute the cd command).

Can someone tell me what I'm doing wrong? (I'm using tmux 1.6)

#!/bin/bash                                                                                                                             
tmux start-server
tmux new-session -d -s my_server -n runstuff

tmux send-keys -t my_server:1 "cd /etc"

tmux select-window -t my_server:1
tmux attach-session -t my_server
like image 483
mark Avatar asked Mar 06 '13 20:03

mark


1 Answers

I finally got it to work, using C-m and numbering the windows starting from 0. I added a second command for illustrative purposes.

#!/bin/bash                                                                                                                             
tmux start-server
tmux new-session -d -s my_server -n runstuff
tmux new-window -t my_server:1 -n someotherjunk

tmux send-keys -t my_server:0 "cd /etc" C-m
tmux send-keys -t my_server:1 "./yolo" C-m

tmux select-window -t my_server:runstuff
tmux attach-session -t my_server
like image 76
mark Avatar answered Oct 14 '22 15:10

mark