我有下面的脚本:
#!/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.
我知道这只是我需要做的语法更改,但不确定如何应用并使其工作。
正如消息所说,您应该使用--
将选项与要执行的命令分开:
for i in 1 2 3; do
options_1+=("$tab" -- bash -c "${cmd_1[i]} ; bash" )
done
同样,你不应该在$tab
值的开头放一个空格。使用
tab="--tab"
你需要像
for i in 1 2 3; do
gnome-terminal $tab -- bash -c "${cmd_1[i]} ; bash"
done
我猜,你需要的是这样的东西-
#!/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个选项卡的新窗口,每个选项卡运行指定的命令,然后保持打开状态。复制粘贴类似的代码,您还可以打开多个窗口,每个窗口有任意数量的选项卡,并在其中运行任意数量的命令。