unix 修复gnome-terminal中的“-e”is deprecated警告

0h4hbjxa  于 2023-10-18  发布在  Unix
关注(0)|答案(3)|浏览(430)

我有下面的脚本。

  1. #!/bin/bash
  2. # Run abc-app services
  3. cd abc-app/packages/auth-service
  4. tab=" --tab"
  5. options_1=()
  6. options_2=()
  7. cmd_1[1]="yarn start"
  8. cmd_1[2]="cd ../../api/shipper; yarn start:shipper"
  9. cmd_1[3]="cd ../../frontend/shipper; yarn dev"
  10. cmd_2[1]="yarn start:procure-app"
  11. cmd_2[2]="yarn start:procure-worker"
  12. cmd_2[3]="yarn start:mail-worker"
  13. cmd_2[4]="yarn start:transporter"
  14. cmd_2[5]="cd ../frontend/shipper; yarn dev"
  15. cmd_2[6]="cd ../frontend/transporter; yarn dev"
  16. for i in 1 2 3; do
  17. options_1+=($tab -e "bash -c '${cmd_1[i]} ; bash'" )
  18. done
  19. for j in 1 2 3 4 5 6; do
  20. options_2+=($tab -e "bash -c '${cmd_2[j]} ; bash'" )
  21. done
  22. gnome-terminal "${options_1[@]}"
  23. cd
  24. cd Documents/Code/abc-procure
  25. gnome-terminal "${options_2[@]}"

当我使用./startServices.sh运行脚本时,它按预期运行,但出现以下警告

  1. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
  2. # Use “-- ” to terminate the options and put the command line to execute after it.
  3. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
  4. # Use “-- ” to terminate the options and put the command line to execute after it.
  5. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
  6. # Use “-- ” to terminate the options and put the command line to execute after it.
  7. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
  8. # Use “-- ” to terminate the options and put the command line to execute after it.
  9. # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
  10. # Use “-- ” to terminate the options and put the command line to execute after it.

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

bbuxkriu

bbuxkriu1#

正如消息所说,您应该使用--将选项与要执行的命令分开:

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

另外,你不应该在$tab的值的开头放一个空格。使用

  1. tab="--tab"
aij0ehis

aij0ehis2#

你需要的是

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

mfuanj7w3#

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

  1. #!/bin/bash
  2. cmd=("echo 1" "echo 2" "echo 3")
  3. final=""
  4. for c in "${cmd[@]}"; do
  5. final+="gnome-terminal --tab -- /bin/bash -c \"${c};bash\";"
  6. done
  7. gnome-terminal --window -- /bin/bash -c "$final"
  8. exit 0

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

相关问题