Is there a way to load the secrets into the local terminal?


Been using doppler for a while and I was wondering if there is a way to load the secrets into the shell. Right now, I find it really annoying having to type doppler run -- npm test or any other command. One alternative would be to create a multiple npm scripts such as npm test and npm ci:test. However managing this gets harder when you have more and more scripts. I was wondering if the following was possible:

  1. Only have one set of scripts (test, dev, start, etc)
  2. When I CD into my local development environment, I run a single command which loads the latest env variables and sources them.
  3. On CI, doppler syncs the env variables so there is no need to use the doppler command there
  4. On prod, same as step 3

Hi there!

We actually have a small section in the docs that discusses this here:

Essentially, you can either create a new shell that was executed via doppler run OR you could setup a script that does this:

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

set -a causes each variable or function that’s defined to be given the export attribute. So, you could have a script that you run in a new shell session that sets all your variables for you.

Would that do what you’re after?


Perfect, thats exactly what I was looking for!

Is there a different way to do this with sh? I added "load": "set -a && source <(doppler secrets download --no-file --format env) && set +a" to my package.json but I get an error saying:

sh: syntax error near unexpected token `('
sh-3.2$ set -a && source <(doppler secrets download --no-file --format env) && set +a

Hi @nahtnam,

There is but I would strongly advise against it because the bourne shell (sh) doesn’t support process substitution (the <() syntax), therefore the secrets would have to be saved to disk and executed in the context of the current shell using the . .env form.

Can you instead install bash?

If not, below is how you could achieve it:

set -a
doppler secrets download --no-file --format env > .env
. .env
unlink .env
set +a

Hi @nahtnam,

I was actually just playing around with this and you might be able to get what you’re after by simply doing this:

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

No set -a or set +a required.

@watsonian Yep, I was the one that emailed you the code for dotenv :slight_smile:

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