修复 gnome-terminal 的“-e”已弃用警告

问题描述 投票:0回答:3

我有以下脚本。

#!/bin/bash

# Run abc-app services
cd abc-app/packages/auth-service

tab=" --tab"
options_1=()
options_2=()

cmd_1[1]="yarn start"
cmd_1[2]="cd ../../api/shipper; yarn start:shipper"
cmd_1[3]="cd ../../frontend/shipper; yarn dev"

cmd_2[1]="yarn start:procure-app"
cmd_2[2]="yarn start:procure-worker"
cmd_2[3]="yarn start:mail-worker"
cmd_2[4]="yarn start:transporter"
cmd_2[5]="cd ../frontend/shipper; yarn dev"
cmd_2[6]="cd ../frontend/transporter; yarn dev"


for i in 1 2 3; do
options_1+=($tab -e "bash -c '${cmd_1[i]} ; bash'" )
done

for j in 1 2 3 4 5 6; do
options_2+=($tab -e "bash -c '${cmd_2[j]} ; bash'" )
done

gnome-terminal "${options_1[@]}"

cd
cd Documents/Code/abc-procure

gnome-terminal "${options_2[@]}"

当我使用

./startServices.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.
# 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.
# 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.

我发现这只是我需要做的语法更改,但不确定如何应用并使其发挥作用。

linux shell unix gnome-terminal
3个回答
0
投票

正如消息所述,您应该使用

--
将选项与要执行的命令分开:

for i in 1 2 3; do
    options_1+=("$tab" -- bash -c "${cmd_1[i]} ; bash" )
done

此外,您不应在

$tab
值的开头添加空格。使用

tab="--tab"

0
投票

你需要类似的东西

for i in 1 2 3; do
    gnome-terminal $tab -- bash -c "${cmd_1[i]} ; bash"
done

0
投票

我想,你需要的是这样的东西 -

#!/bin/bash

cmd=("echo 1" "echo 2" "echo 3")

final=""

for c in "${cmd[@]}"; do
    final+="gnome-terminal --tab -- /bin/bash -c \"${c};bash\";"
done

gnome-terminal --window -- /bin/bash -c "$final"

exit 0

这将打开一个包含 3 个选项卡的新窗口,每个选项卡运行指定的命令,然后保持打开状态。复制粘贴类似的代码,您还可以打开多个窗口,每个窗口都有任意数量的选项卡,并在其中运行任意数量的命令。

© www.soinside.com 2019 - 2024. All rights reserved.