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

**URL:** <https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419>\
**Category:** Need Help\
**Created:** [November 22, 2021, 3:33am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419 "2021-11-22T03:33:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nahtnam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/nahtnam/32/282_2.png) [@nahtnam](https://community.doppler.com/u/nahtnam)\
**Post date:** [November 22, 2021, 3:33am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/1 "2021-11-22T03:33:40Z")

</div>

Hello!

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

---

<div class="post-metadata">

**Author:** ![watsonian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/watsonian/32/267_2.png) [@watsonian](https://community.doppler.com/u/watsonian)\
**Post date:** [November 22, 2021, 5:42pm UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/2 "2021-11-22T17:42:50Z")

</div>

Hi there!

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

> **[Getting Secrets](https://docs.doppler.com/docs/accessing-secrets#how-to-export-doppler-secrets-into-the-current-shell)**
>
> reading time 3 minutes

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

```auto
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 `pull-env-secrets.sh` script that you run in a new shell session that sets all your variables for you.

Would that do what you’re after?

-Joel

---

<div class="post-metadata">

**Author:** ![nahtnam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/nahtnam/32/282_2.png) [@nahtnam](https://community.doppler.com/u/nahtnam)\
**Post date:** [November 23, 2021, 2:39am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/3 "2021-11-23T02:39:07Z")

</div>

Perfect, thats exactly what I was looking for!

---

<div class="post-metadata">

**Author:** ![nahtnam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/nahtnam/32/282_2.png) [@nahtnam](https://community.doppler.com/u/nahtnam)\
**Post date:** [November 23, 2021, 2:46am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/4 "2021-11-23T02:46:16Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [November 23, 2021, 12:17pm UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/5 "2021-11-23T12:17:40Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![watsonian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/watsonian/32/267_2.png) [@watsonian](https://community.doppler.com/u/watsonian)\
**Post date:** [December 6, 2021, 5:32pm UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/6 "2021-12-06T17:32:49Z")

</div>

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:

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

```

No `set -a` or `set +a` required.

---

<div class="post-metadata">

**Author:** ![nahtnam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/nahtnam/32/282_2.png) [@nahtnam](https://community.doppler.com/u/nahtnam)\
**Post date:** [December 7, 2021, 2:52am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/7 "2021-12-07T02:52:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [December 7, 2021, 2:56am UTC](https://community.doppler.com/t/is-there-a-way-to-load-the-secrets-into-the-local-terminal/419/8 "2021-12-07T02:56:44Z")

</div>

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