我想在不同的选项卡/终端上的同一个 shell 脚本中运行一些命令



我实际上想在不同的选项卡或终端上运行相同脚本的一些命令,因为这些命令正在激活服务器并侦听不同的端口。所以他们必须始终保持活跃。同样,我希望引用选项卡或终端,以便以后可以在脚本末尾关闭它们。请帮忙。

我尝试了一个简单的脚本测试,看看我是否能找到打开其他选项卡的方法:

tab=" --tab"
options=()
cmds[1]="echo Banana"
cmds[2]="echo Cat"

for i in 1 2; do
options+=($tab  -e "bash -c "${cmds[i]} ; bash"" ) 
done
gnome-terminal "${options[@]}"
exit 0

但我得到这个结果:

./test.sh
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.

有没有办法打开标签? 并获取对每个选项卡的引用,以便我可以在处理完成后关闭与服务器相关的命令?

你可以使用一个名为tmux的程序。这是一个像屏幕一样的terminal-mu ltiplexer。有了它,您可以在同一个终端窗口中打开不同的会话和窗口(这些就像选项卡(。可以通过脚本按名称或 id 引用它们。

很有可能,您的 Linux 发行版的包管理器tmux.

PS:我必须发布答案而不是评论,因为我没有足够的声誉发表评论。

这是我为侏儒终端找到的;我认为这可能会有所帮助,谢谢

gnome-terminal(1)           General Commands Manual          gnome-terminal(1)
NAME
gnome-terminal — is a terminal emulation application.
SYNOPSIS
gnome-terminal  [-e,  --command=STRING]   [-x,  --execute ]  [--window-
with-profile=PROFILENAME]  [--tab-with-profile=PROFILENAME]  [--window-
with-profile-internal-id=PROFILEID]       [--tab-with-profile-internal-
id=PROFILEID]    [--role=ROLE]    [--show-menubar]     [--hide-menubar]
[--geometry=GEOMETRY]  [--working-directory=DIRNAME]  [-?, --help]
DESCRIPTION
GNOME  Terminal is a terminal emulation application that you can use to
perform the following actions:
Access a UNIX shell in the GNOME environment.
A shell is a program that interprets and executes the commands that you
type  at  a  command  line  prompt.  When you start GNOME Terminal, the
application starts the default shell that is specified in  your  system
account. You can switch to a different shell at any time.
OPTIONS
-e, --command=STRING
Execute the argument to this option inside the terminal.
-x, --execute
Execute  the  remainder of the command line inside the termi‐
nal.
--window-with-profile=PROFILENAME
Open a new window containing a tab with  the  given  profile.
More than one of these options can be provided.
--tab-with-profile=PROFILENAME
Open  a  tab  in the window with the given profile. More than
one of these options can be provided, to open several tabs .
--window-with-profile-internal-id=PROFILEID
Open a new window containing a tab with the given profile ID.
Used internally to save sessions.

最新更新