从周期打开多个标签页在GNOME终端与复杂的命令 [英] Opening multiple tabs in gnome terminal with complex commands from a cycle

查看:142
本文介绍了从周期打开多个标签页在GNOME终端与复杂的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要的命令被称为是这样的:

I have a command that needs to be called like this:

command "complex argument"

如果我想运行GNOME终端传递给它这样的说法,它是这样的:

If I want to run gnome-terminal passing it this argument, it goes like this:

gnome-terminal -e 'command "complex argument"'

我要在终端上打开多个标签页,执行与不同的参数,每次这个命令。这个工作是这样的:

I want to open multiple tabs in the terminal, executing this command with different arguments each time. This works this way:

gnome-terminal -e 'command "complex argument1"' --tab -e 'command "complex argument2"'

但问题来了,如果我想用一个脚本,在那里我得到每个标签页的参数从一个周期去执行它(即标签的数量是可变的)。我的基本想法是,我收集的参数一个变量,然后通过它来Gnome终端。但我不知道如何做到这一点使所有的嵌套报价参数不变。要么一切都是COM pressed在一个参数(如果我叫 Gnome终端的$ args),或者由每个空白分崩离析(如果我叫的gnome-terminal的$ args )。

But the problem comes if I want to execute it with a script, where I get the parameters for each tabs from a cycle (i.e. the number of tabs is variable). My basic idea was that I collect the arguments to a single variable, then pass it to gnome-terminal. But I don't know how to do this leaving all the nested quoted arguments intact. Either everything is compressed in one argument (if I call gnome-terminal "$args"), or it falls apart by every whitespace (if I call gnome-terminal $args).

有没有办法在bash组合这类复杂的参数呢?或者,有没有什么办法来发送IPC消息Gnome终端,告诉它打开一个新标签,并执行命令?我知道我可以用Konsole的做到这一点,但现在我想用GNOME终端做到这一点。

Is there any way to compose such complex arguments in bash? Or, alternatively, is there any way to send IPC messages to gnome-terminal, telling it to open a new tab and execute a command? I know I can do this with Konsole, but now I want to do it with gnome-terminal.

推荐答案

我找到了解决办法:数组。他们可以做的魔术。

I found the solution: arrays. They can do magic.

# initial arguments
command=(gnome-terminal -e 'command "complex argument"')
...
# add extra arguments
command=("${command[@]}" --tab -e 'command "complex argument2"')
...
# execute command
"${command[@]}"

这篇关于从周期打开多个标签页在GNOME终端与复杂的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆