简单的 tmux bash 脚本不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15257130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
simple tmux bash script not working
提问by mark
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).
我想让 tmux 打开一个新窗口,然后 cd 进入一个目录,但它不起作用。它只是在运行我的脚本的目录中打开 tmux(即它不执行 cd 命令)。
Can someone tell me what I'm doing wrong? (I'm using tmux 1.6)
有人可以告诉我我做错了什么吗?(我正在使用 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
回答by mark
I finally got it to work, using C-m and numbering the windows starting from 0. I added a second command for illustrative purposes.
我终于让它工作了,使用 Cm 并从 0 开始为窗口编号。为了说明目的,我添加了第二个命令。
#!/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
回答by chepner
send-keyssimulates typing at the keyboard. As such, you need to send the Enterkey as well.
send-keys模拟在键盘上打字。因此,您还需要发送Enter密钥。
tmux send-keys -t my_server:1 "cd /etc\n"

