我是 tmux 的新手,当我尝试时发现这种行为非常奇怪。
我写了一个非常简单的脚本
tmux new-session -s "test" -d
tmux send-keys -t test hello Enter
tmux attach -t "test"
当我运行它时,shell 显示以下内容
hello
eric:bin$ hello
我只希望“hello”命令在提示符内显示一次,但“hello”命令将显示两次:一个在提示符外,一个在提示符内
有谁知道原因?
最佳答案
我不认为这是 tmux
问题。发生的事情是tmux
在 shell 完成加载之前将 key 发送到窗口。
您可以通过执行以下操作来查看该现象:
$ sleep 3
hello
$ hello
bash: hello: command not found
而
sleep 3
正在运行时,您可以键入“hello”+ Enter 并且只有在该程序完成运行时,bash
解释输入。您可以通过加快 shell 加载速度来解决此问题。
关于tmux send-keys 命令在屏幕上出现两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30413047/