[英]How to run tmux with shell command
I want to run tmux with shell command in it我想在其中运行带有 shell 命令的 tmux
I try: tmux new-session -d -s foo 'echo intmux'
( I want to use this later in bash script)我尝试:
tmux new-session -d -s foo 'echo intmux'
(我想稍后在 bash 脚本中使用它)
But it doesn't works.但它不起作用。 I expect that:
我希望:
1) Tmux open new window ( like tmux new ) 1) Tmux 打开新的 window ( 像 tmux new )
2) command echo intmux
will be called 2) 将调用命令
echo intmux
1) Tmux open new window ( like tmux new )
1) Tmux 打开新的 window ( 像 tmux new )
You will not see a new session, because you create it using -d
(detached) flag.您不会看到新的 session,因为您使用
-d
(分离)标志创建它。
What you want (execute a command and leave a shell open) can be easily achieved with:您想要的(执行命令并让 shell 打开)可以通过以下方式轻松实现:
tmux new -s foo 'echo intmux; $SHELL'
Another tricky option bound to specific (bash) shell:绑定到特定(bash)shell 的另一个棘手选项:
tmux new-session -s foo 'bash --rcfile <(echo ". ~/.bashrc; echo intmux")'
This allows to preserve default behavior (reading . ~/.bashrc
) and pass your arbitrary command.这允许保留默认行为(读取
. ~/.bashrc
)并传递您的任意命令。
You can run你可以跑
tmux new-session '-s foo' \; neww '-t 2 -n echo' mc
But that spawns another window in the new session running your command so possibly you want to close the first window但这会在运行您的命令的新 session 中产生另一个 window ,因此您可能想关闭第一个 window
tmux new-session '-s foo' \; neww '-n echo' mc \; kill-window '-t 1'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.