bash - Shell 脚本打开多个终端并执行不同的命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22656359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:45:07  来源:igfitidea点击:

bash - Shell script opening multiple terminals and executing distinct commands

bashshellunixterminal

提问by itachi42

I've tried to write my own shell script. So far I've managed to open 4 xterminals that can only execute ONE command because of the 'hold' option.

我尝试编写自己的 shell 脚本。到目前为止,由于 'hold' 选项,我已经设法打开了 4 个只能执行一个命令的 xterminal。

If i don't use this option, the terminals just disappear.

如果我不使用这个选项,终端就会消失。

Here is my code :

这是我的代码:

#!/bin/sh
xterm -title "App 1" -hold -e mycommand | mysecondcommand  &
xterm -title "App 2" -hold -e mycommand | mysecondcommand  &
xterm -title "App 3" -hold -e mycommand | mysecondcommand  &
xterm -title "App 4" -hold -e mycommand | mysecondcommand

Not so sure if I'm supposed to execute the second command in the same terminal that way.

不太确定我是否应该以这种方式在同一个终端中执行第二个命令。

Any ideas ?

有任何想法吗 ?

Thank you

谢谢

回答by Josh Jolly

Without -hold, the xterm will close as soon as the command is completed. You can execute multiple commands by using double quotes and command separators (eg ;, &):

如果没有-hold,xterm 将在命令完成后立即关闭。您可以使用双引号和命令分隔符(例如;, &)来执行多个命令:

xterm -title "App 1" -e "mycommand; mysecondcommand"