bash tmux - 附加到会话并指定窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24100721/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:38:10  来源:igfitidea点击:

tmux - attach to a session and specify window

bashsessioncentosshtmux

提问by user3707440

I have a script (.sh) and I want it to run in a existing tmux session. I have 1 session with 8 windows in.

我有一个脚本 (.sh),我希望它在现有的 tmux 会话中运行。我有 8 个窗口的 1 个会话。

Is there a command like tmux a -t session-name, which also specify the window?

是否有类似的命令tmux a -t session-name,它也指定了窗口?

And would a script like this work?

像这样的脚本会起作用吗?

#!/bin/bash tmux a -t session-name #What ever to write to specify window# java -jar -Xmx4G -Xms4G Spigot.jar

#!/bin/bash tmux a -t session-name #What ever to write to specify window# java -jar -Xmx4G -Xms4G Spigot.jar

回答by chepner

You can change the active window of a session beforeyou attach to the session.

您可以附加到会话之前更改会话的活动窗口。

tmux -t <session-name> select-window -t <windowID>
tmux a -t <session-name>

You can combine two tmuxcommands as well.

您也可以组合两个tmux命令。

tmux -t session-name select-window -t <windowID> \; a

If you really want to run java, presumably you want to create a new window with new-window, rather than select an existing one with select-window.

如果你真的想运行java,大概你想用 来创建一个新窗口new-window,而不是用 来选择一个现有的窗口select-window



Newer versions of tmux(at least 1.9; did the above ever work, perhaps in 1.6?) no longer appear to have a -toption to specify the session to apply commands to. Instead, each individual command specifies the session.

较新版本的tmux(至少 1.9;上述是否有效,也许在 1.6 中?)似乎不再具有-t指定要应用命令的会话的选项。相反,每个单独的命令都指定会话。

tmux select-window -t <session-name>:<windowID> \; a -t <session-name>

回答by dowewas

For tmux version 2.1 this works

对于 tmux 2.1 版,这有效

tmux a -t  <session-name> \; select-window -t <windowID> \;