Doppler in script shebang

It would be great to be able to use doppler in the script shebang. On MacOS, this actually works

#!/usr/bin/env doppler run -- /bin/bash

But then you get a nasty surprise on linux—no support for shebang args! So then you have to do this:

set -euo pipefail
quoted_args="$(printf "${1+ %q}" "$@")"
bash_script="$(tail -n +9 $bash_source)"
doppler run --command="/bin/bash -c '$bash_script_with_variables'"
exit 0

# workaround for #!/usr/bin/env doppler run -- /bin/bash
# - no arguments on linux
# - fail on error "set -euo pipefail"
# - quoted args
# - skip lines
# - bash source
# - concat variables with newline
# - bash -c

It’s long and ugly, but it works. I’d love for doppler to have a bin script that is basically just bash with the right env.

Hi there!

You might find this helpful:

Essentially, you do this:

set -a
source <(doppler secrets download --no-file --format env)
set +a

set -a causes all the environment variables set to be exported. Putting that at the top of your script should populate all your variables without having things get too messy for you!

1 Like

Hmm, that doesn’t seem to be working

Found a workaround

Ah, did you end up doing something like this?

export $(doppler secrets download --no-file --format env-no-quotes)

I think that might accomplish what you’re after too.

Kinda, ended up with:

export $(doppler secrets download --no-file --format env | xargs)

One caveat to the export $(...) form is that it will fail if there is a space in a secret’s value.

Quite a caveat! That’s what I experienced