如何在循环内附加到屏幕会话?
我使用 bash 脚本以“分离”模式生成屏幕会话(使用 -d -m 选项) 并命名它们(通过 -S ),然后我附加到它们以给出一些命令 (通过 -r ):
#!/bin/bash
screen -d -m -S session_name_1
screen -d -m -S session_name_2
screen -d -m -S session_name_3
...
screen -r session_name_1
screen -r session_name_2
screen -r session_name_3
当我以循环方式执行整个过程时,我无法附加到屏幕 (文件 session_names.txt 是一个每行包含一个会话名称的文件):
#!/bin/bash
while read line; do
echo $line
screen -d -m -S $line
done < session_names.txt
while read line; do
echo $line
screen -r $line
done < session_names.txt
我无法附加到屏幕,并且发生此错误:
“必须连接到终端。”
我该如何克服这个问题以及为什么会出现这个问题?
I use a bash script to spawn screen sessions in "detached" mode (using -d -m options)
and name them (through -S ) and then I attach to them to give some commands
(through -r ):
#!/bin/bash
screen -d -m -S session_name_1
screen -d -m -S session_name_2
screen -d -m -S session_name_3
...
screen -r session_name_1
screen -r session_name_2
screen -r session_name_3
when I do the whole process in a loop fashion I cannot attach to a screen
(the file session_names.txt is a file whose each line contains a session name):
#!/bin/bash
while read line; do
echo $line
screen -d -m -S $line
done < session_names.txt
while read line; do
echo $line
screen -r $line
done < session_names.txt
I can't attach to a screen and this error occurs:
"Must be connected to a terminal."
How I can overcome this problem and why this problem occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在整个循环中,标准输入来自txt文件,因此屏幕看不到终端。
这应该可以做到,但请注意,这里的“行”实际上意味着“单词”。
In the whole loop the standard input comes from the txt file, so screen is not seeing the terminal.
This should do it, but note that 'line' really means 'word' here.