简体   繁体   English

gnome-terminal从文件执行命令

[英]gnome-terminal executes commands from file

I need an example of gnome-terminal command to read lines of text from a file and executes them one by one in different terminal or a tab. 我需要一个gnome-terminal命令示例,以从文件中读取文本行,并在不同的终端或选项卡中逐行执行它们。

So this would be the process. 所以这就是过程。 I would run gnome terminal command and it would read 10 commands from a file. 我将运行gnome terminal命令,它将从一个文件读取10条命令。 Then it would execute those 10 commands in 10 different tabs/terminals. 然后它将在10个不同的选项卡/终端中执行这10条命令。 And of course those tabs/terminals would remain opened. 当然,这些选项卡/终端将保持打开状态。 I found this question Avoid gnome-terminal close after script execution? 我发现了这个问题避免在脚本执行后关闭gnome-terminal?

The third answer from the top is very helpful. 顶部的第三个答案非常有帮助。 I managed to open 1 command from a file. 我设法从文件中打开1条命令。 But I need 1 file with 10 command lines to be opened like I wrote above. 但是我需要像上面写的那样打开带有10个命令行的1个文件。

Thanks. 谢谢。

I recommend to use screen for this, if that can be acceptable to you. 如果您可以接受,我建议使用screen

You could create a commands.screenrc file like this: 您可以创建一个commands.screenrc文件,如下所示:

screen bash -c 'command1; echo press any key; read'
screen bash -c 'command2; bash'
screen mutt
screen emacs
screen

You can define as many programs as you want. 您可以根据需要定义任意数量的程序。 Start screen with: 开始screen

screen -c commands.screenrc

I don't know what kind of commands you want to run. 我不知道您要运行哪种命令。 If you want to see their output, then write like the first example above: execute the command in a bash shell, which will "pause" after the command was executed. 如果要查看它们的输出,请像上面的第一个示例一样编写:在bash shell中执行命令,该命令执行后将“暂停”。 Or the second line, which, after running the command will start another bash shell. 或第二行,在运行命令后,它将启动另一个bash shell。 Otherwise the screen window would exit automatically. 否则,屏幕窗口将自动退出。

If you are not familiar with screen , you will need to learn some basic key strokes to get around, and to be able to switch between windows. 如果您不熟悉screen ,那么您将需要学习一些基本的击键操作,以便能够在窗口之间切换。 The first few pages of this presentation should be enough to get you started. 本演示文稿的前几页应该足以让您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM