> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/export-ser-var-as-env-var.md).

# Export service variables as environment variables in a Shell Script step

Learn how to export service variables as environment variables when using a Shell Script step

You can use the **Export Service Variables as Env Variables** setting to export service variables as environment variables. This setting is available at account, organization, and project levels.

## What you will learn from this topic

* How to [enable the export setting](#enable-the-export-setting) so that service variables are available in a Shell Script step
* Understand [how service variable types and special characters behave](#example-service-variables) when exported as environment variables
* How to [verify the exported values](#verify-the-exported-values) after you run a pipeline

## Enable the export setting

To enable this setting, go to **Account Settings** -> **Account Resources** -> **Default Settings** -> **Pipeline**, and then expand **Pipeline**. Next, set the **Export Service Variables as Env Variables** setting to `true`.

Once you enable this setting, a service's variables are available as Bash variables in any Shell Script step in a stage that deploys that service. You can access the service variables like you access any Bash variables. For example, the service variable, `var1` is available for use in a Shell Script step as `$var1`.

## Example service variables

When you [add a service variable](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/add-a-variable), you can select variables of type **String**, **Secret**, or **Number**.

Consider an example where you have added the following service variables:

| **Variable name**  | **Type** | **Value**                |
| ------------------ | -------- | ------------------------ |
| `svar1`            | String   | normalValue              |
| `svar2`            | String   | value-with-hyphen        |
| `svar3`            | String   | value\_with\_underscores |
| `secretServiceVar` | Secret   | `yourSecret`             |
| `nvar1`            | Number   | 1                        |
| `svar4`            | String   | abc%def%123              |
| `svar5$abc`        | String   | key\_With\_Dollar        |
| `svar6`            | String   | abc,ghj,klk              |

In your Shell Script step, you can use these service variables as environment variables if you have enabled the **Export Service Variables as Env Variables** setting.

{% hint style="info" %}
**LIMITATION**

Shell scripts executing on remote hosts cannot export the correct value if you are using special characters such as `-`, `_`, `$`, `%`, and spaces in Bash.
{% endhint %}

## Verify the exported values

When you run the pipeline, you can see the value of the service variables passed as environment variables.

![Shell Script step output showing the service variables passed as environment variables](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-25ffb0d565f2be9070917ab5086e2303899f0180%2Fexport-srv-var-as-env-var.png?alt=media)

## Next steps <a href="#see-also" id="see-also"></a>

* [Using Shell Script steps in CD stages](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/utilities/shell-script-step.md)
* [Define variables](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/add-a-variable)
* [Services overview](/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/services-overview.md)
* [Environments overview](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/environment-overview.md)

{% @harness-feedback/feedback %}
