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

时间:2019-08-15 09:23:52

标签: linux bash shell terminal scripting

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

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

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.

有什么办法可以打开标签页?并获得对每个服务器的引用,以便在处理完成后关闭与服务器相关的命令?

2 个答案:

答案 0 :(得分:2)

您可以使用名为tmux的程序。这是 t 最终版- mu 成品 x er ,例如 screen 。这样,您可以在同一终端窗口中打开不同的会话和窗口(如选项卡)。可以通过脚本按名称或ID引用它们。

您的Linux发行版的软件包管理器很有可能具有tmux

P.S:我没有评论的美誉,所以我必须发表答案而不是发表评论。

答案 1 :(得分:0)

这是我对man gnome-terminal的发现;我认为可以帮上忙,谢谢

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.