【问题标题】:Working around "expanding an array only gives first element" (SC2128)Working around \"expanding an array only gives first element\" (SC2128)
【发布时间】:2022-12-02 00:55:00
【问题描述】:

Problem

I'm trying to save a few CLI arguments into a variable, so it's convenient for me to use later. This works but is quite verbose:

  • flutter run --dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY} --dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}

Unfortunately, neither of the following, concise options work. The 2nd --dart-define is not available in the app. I've tried:

  • flutter run $APP1_DART_DEFINE_FLAGS
  • flutter run "${APP1_DART_DEFINE_FLAGS[@]}"

How do I workaround an issue which seems to be inside the flutter run tool?


Related problems

This seems to be highly related to (but I don't have control over fixing this):

My env file

export APP1_SENTRY_DS=...
export APP1_MAPBOX_ACCESS_TOKEN=...
export APP1_DART_DEFINE_FLAGS="--dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY} --dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}"

【问题讨论】:

  • in your env file you define APP1_SENTRY_DS but when defining APP1_DART_DEFINE_FLAGS you reference a different variable APP1_SENTRY_DSN_CLIENT_KEY; I can't tell if you have a typo in the env file, a typo in what you've posted in the question, or if there are more entries in your env file that are not shown here ... ??
  • nowhere in the question do you show the creation/population of an array so not sure where the reference to SC21281 comes into play here; did you generate the SC2128 and if so could you provide the complete set of code you supplied to shellcheck.net?

标签: bash


【解决方案1】:

Use bash arrays. Properly quote arguments.

APP1_DART_DEFINE_FLAGS=(
   "--dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY}"
   "--dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}"
)
flutter run "${APP1_DART_DEFINE_FLAGS[@]}"

【讨论】:

    猜你喜欢
    • 2018-09-18
    • 2016-07-07
    • 2021-03-17
    • 2018-03-25
    • 2018-11-24
    • 2011-04-19
    • 2022-12-26
    • 1970-01-01
    • 2014-05-25
    相关资源
    最近更新 更多