【发布时间】:2021-04-06 09:59:48
【问题描述】:
我创建了一个 bash 脚本来打开多个终端。但是,在打开所有终端并运行第一个命令后,我无法访问它们并在我选择的终端上执行我想要的命令。例如,在我发布的代码运行后,我想在标题为“node5”的终端上运行insert Hi, 1 命令。我可以这样做吗?我当前的代码如下:
#!/bin/bash
printf "$FBOLD\nPlease enter the port: $FREG"
read invalue
xterm -title "node1" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node2" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node3" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node4" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node5" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node6" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node7" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node8" -hold -e "node index.js localhost:${invalue}" &
sleep 1
xterm -title "node9" -hold -e "node index.js localhost:${invalue}" &
sleep 1
编辑:为了更清楚。我想通过 bash 脚本执行命令,因为我想在每个终端中进行数百次插入。所以这个过程应该是自动化的。
【问题讨论】:
-
难道你没有一个鼠标,你可以在代表“带有标题 node5 的终端”的窗口上“单击”吗?
-
@KamilCuk 是的,但我想做数百个插入,所以我想自动化这个过程
-
你为什么首先使用
xterm?为什么不是你可以真正自动化的东西?喜欢screen或tmux。 -
@KamilCuk 我不知道该怎么做。你能写一个关于它的答案吗?我搜索了很多,但没有出现
-
但是,你还是不能运行
echo "insert Hi, 1" | node ....吗?您是否有任何理由需要运行 interactive shell?为什么不以非交互方式运行它?