tmux send-keys 命令在屏幕上出现两次

web*_*uma 6 sendkeys tmux

我是 tmux 的新手,当我尝试它时发现这种行为非常奇怪。

我写了一个非常简单的脚本

tmux new-session -s "test" -d
tmux send-keys -t test hello Enter
tmux attach -t "test" 
Run Code Online (Sandbox Code Playgroud)

当我运行它时,shell 显示以下内容

hello
eric:bin$ hello
Run Code Online (Sandbox Code Playgroud)

我只希望“hello”命令在提示符内显示一次,但“hello”命令将显示两次:一次在提示符外,一次在提示符内

有谁知道原因吗?

ton*_*his 5

我认为这不是tmux问题。发生的情况是tmux在 shell 完成加载之前将密钥发送到窗口。

您可以通过执行以下操作来查看该现象:

$ sleep 3
hello
$ hello
bash: hello: command not found
Run Code Online (Sandbox Code Playgroud)

在运行时,sleep 3您可以键入“hello”+ Enter,只有当该程序完成运行时,bash才会解释输入。

您可以通过加快 shell 加载速度来解决此问题。