# Passing environment variable to orb command

**URL:** <https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000>\
**Category:** Orbs\
**Created:** [August 9, 2022, 1:14pm UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000 "2022-08-09T13:14:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andarius](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/andarius/32/30795_2.png) [@Andarius](https://discuss.circleci.com/u/Andarius)\
**Post date:** [August 9, 2022, 1:14pm UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/1 "2022-08-09T13:14:10Z")

</div>

Hi,

I have a command that is using a string parameter that will be stored as en environment variable so that the `include` script can use it.  
Here is the command:

**sre-utils/test**

```auto
parameters:
  registry_user:
    default: ''
    type: string

steps:
  - run:
      name: test
      command: echo << parameters.registry_user >>

  - run:
      name: test2
      environment:
        CONTAINER_REGISTRY_USER: << parameters.registry_user >>
      command: << include(myscript.sh) >>

```

**myscript.sh**

```auto
#!/bin/bash
echo "${CONTAINER_REGISTRY_USER}"

```

And I’m calling it by passing the following to the job:

```auto
      - sre-utils/test:
          registry_user: ${MY_VAR}

```

However, if **test** will echo “\*\*\*\*\*\*\*”, **test2** will output

```auto
+ echo '${CONTAINER_REGISTRY_USER}'
${MY_VAR}

```

Do you know what I’m doing wrong here ?

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [August 9, 2022, 6:30pm UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/2 "2022-08-09T18:30:15Z")

</div>

The “\*\*\*\*\*\*” output within the logs is normal as the system tries its very best to hide all parameters and job-based environment variables as a security measure. It’s a nice feature, but a real pain when trying to debug things.

This hiding process does not take place on variables that are defined within bash scripts as the build process is not tracking the assigned values. More details can be found here

> **[Using Environment Variables - CircleCI](https://circleci.com/docs/env-vars)**
>
> A list of supported environment variables in CircleCI

---

<div class="post-metadata">

**Author:** ![Andarius](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/andarius/32/30795_2.png) [@Andarius](https://discuss.circleci.com/u/Andarius)\
**Post date:** [August 10, 2022, 6:55am UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/3 "2022-08-10T06:55:15Z")

</div>

Hey, thanks for the answer.  
My question is mainly why am I seeing `${MY_VAR}` and not the actual value like if `foo` if `MY_VAR=foo`.  
Do you have an idea why ?

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [August 10, 2022, 9:01am UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/4 "2022-08-10T09:01:45Z")

</div>

OK, I missed that part

The circleci script environment is not a Linux shell, with the result that it does not currently do environment variable expansion as you would hope/expect. So passing ${MY\_VAR} will pass “${MY\_VAR}” rather than the value of MY\_VAR. Circleci states

" In general, CircleCI does not support interpolating environment variable into build config. Values used are treated as literals. This can cause issues when defining `working_directory`, modifying `PATH`, and sharing variables across multiple `run` steps."

---

<div class="post-metadata">

**Author:** ![Andarius](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/andarius/32/30795_2.png) [@Andarius](https://discuss.circleci.com/u/Andarius)\
**Post date:** [August 10, 2022, 9:03am UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/5 "2022-08-10T09:03:46Z")

</div>

Thanks, I’ll revert back to not using the script then.

---

<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:** [August 20, 2022, 9:03am UTC](https://discuss.circleci.com/t/passing-environment-variable-to-orb-command/45000/6 "2022-08-20T09:03:55Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
