0

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_DSN_CLIENT_KEY=...
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}"
markp-fuso
  • 28,790
  • 4
  • 16
  • 36
Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
  • 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 ... ?? – markp-fuso Dec 01 '22 at 16:49
  • 1
    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? – markp-fuso Dec 01 '22 at 16:56
  • **1.** Sorry @markp-fuso, that's a typo in the question. It doesn't look like that on my computer. I've fixed that. **2.** I did get that warning from shellcheck.net which is what prompted me to write that. I can't reproduce it now – Ben Butterworth Dec 01 '22 at 17:25

1 Answers1

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[@]}"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • I've confirmed the variable can be expanded well (`echo "${APP1_DART_DEFINE_FLAGS[@]}"`), however the 2nd environment variable is still not available in the app. I tried in both bash and zsh. – Ben Butterworth Dec 01 '22 at 17:26
  • @BenButterworth add `set -xv` (enable debugging) just before `flutter` call, run script again, and review the debug output; does the array reference get expanded correctly? wondering if this is a `bash` issue or a `flutter` issue – markp-fuso Dec 01 '22 at 17:37
  • Oh, I've just tried it again. And it works fine. Thanks a lot for your help and attention. So the problem was I wasn't creating an array. But why wasn't my definition of `APP1_DART_DEFINE_FLAGS` okay? – Ben Butterworth Dec 01 '22 at 18:50
  • Also, is there a way to access `APP1_DART_DEFINE_FLAGS` in a `Makefile`. Look's like it doesn't show up . – Ben Butterworth Dec 01 '22 at 19:07