# Can't access environment variables in shell scripts

**URL:** <https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454>\
**Category:** Build Environment\
**Tags:** envars\
**Created:** [February 19, 2017, 6:03am UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454 "2017-02-19T06:03:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktstowell](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ktstowell/32/15479_2.png) [@ktstowell](https://discuss.circleci.com/u/ktstowell)\
**Post date:** [February 19, 2017, 6:03am UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/1 "2017-02-19T06:03:18Z")

</div>

Hi all!

I’m new to CircleCi so hopefully I’m just missing something obvious but I can’t seem to access any of the environment variables I created in the settings GUI.

Say I have the config of:

deployment:  
branch: development  
commands:

- ./myscript.sh

The script runs and but anytime I try and access an environment variable with $MY\_ENV\_VAR it is empty.

(also, fwiw `printenv` works and doesn’t show my custom env variables either.)

Is this even possible?

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![ericnakagawa](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ericnakagawa/32/16025_2.png) [@ericnakagawa](https://discuss.circleci.com/u/ericnakagawa)\
**Post date:** [May 1, 2017, 9:37pm UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/2 "2017-05-01T21:37:27Z")

</div>

Did you find a resolution or workaround for this?

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [May 1, 2017, 10:39pm UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/3 "2017-05-01T22:39:10Z")

</div>

Seeing this I think of the following questions:

1. How are you setting these variables?
2. Are the variable names using anything other than alphanumeric characters?
3. Is this a fork/PR build?
4. Was a new build (from a new commit) done in order to test for the environment variable?

---

<div class="post-metadata">

**Author:** ![ericnakagawa](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ericnakagawa/32/16025_2.png) [@ericnakagawa](https://discuss.circleci.com/u/ericnakagawa)\
**Post date:** [May 1, 2017, 10:53pm UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/4 "2017-05-01T22:53:02Z")

</div>

1. Setting in GUI on [Circleci.com](http://Circleci.com) for Jest repo.
2. No, just alpha numeric keys.
3. This is a PR build and I’m SSHing into the session. In my case I am unable to echo $ENVVAR.
4. These keys have been here prior.

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [May 2, 2017, 7:08am UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/5 "2017-05-02T07:08:11Z")

</div>

@ericnakagawa and @ktstowell can you take a look at this post and let me know if its the same issue that I answered there: [Gemnasium and CircleCI - GEMNASIUM\_TOKEN seems to not get picked up](https://discuss.circleci.com/t/gemnasium-and-circleci-gemnasium-token-seems-to-not-get-picked-up/12294/2)

If this is **not** a forked PR build, please give me a build URL so I can take a look.

---

<div class="post-metadata">

**Author:** ![ericnakagawa](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ericnakagawa/32/16025_2.png) [@ericnakagawa](https://discuss.circleci.com/u/ericnakagawa)\
**Post date:** [May 2, 2017, 4:57pm UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/6 "2017-05-02T16:57:50Z")

</div>

Ah, yes. In my case it is a forked PR! The justification makes sense. Any way for this to be added to docs?

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [May 4, 2017, 11:30pm UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/7 "2017-05-04T23:30:50Z")

</div>

Where would you expect to see this information being added in Docs? To the page about environment variables? A page explaining all about forks and PRs and how settings might change? Something else?

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [May 5, 2017, 5:36am UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/8 "2017-05-05T05:36:49Z")

</div>

This is actually in the docs, but might be buried away somewhere. [https://circleci.com/docs/1.0/fork-pr-builds/#security-implications](https://circleci.com/docs/1.0/fork-pr-builds/#security-implications)

cc @FelicianoTech maybe we can find a better place to put this?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:39am UTC](https://discuss.circleci.com/t/cant-access-environment-variables-in-shell-scripts/10454/9 "2018-06-18T11:39:11Z")

</div>


