# Set Linux shell environment variable

**URL:** <https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762>\
**Category:** General\
**Created:** [28 February 2021 17:59 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762 "2021-02-28T17:59:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcaccount](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dcaccount](https://discourse.nodered.org/u/dcaccount)\
**Post date:** [28 February 2021 17:59 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762/1 "2021-02-28T17:59:17Z")

</div>

Hello,  
in Node Red I need to set a Linux Shell environment variable, for instance SPEAKVOL=10

I tried everything, also to create a shell file:

```auto
#!/bin/sh
export SPEAKVOL=$1

```

and then adding an exec node with the command

> source name\_of\_above\_file.sh

but it is not working.  
How can I do? Please help!

Thanks,  
Dan

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [1 March 2021 02:21 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762/2 "2021-03-01T02:21:17Z")

</div>

You could set the environment variable in the settings file as explained in below link.

> [@How to set env variable](https://discourse.nodered.org/t/how-to-set-env-variable/18612/5):
>
> One way of setting environment variables is in your settings.js file. The following will set the env var MY\_ENV\_VAR: process.env.MY\_ENV\_VAR = "Hello World"; You can add lines like that to the top of your settings file. The other option is to set them completely outside of Node-RED in shell you are running Node-RED in. How you do that will depend on your OS and how you are running Node-RED.

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [1 March 2021 05:35 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762/3 "2021-03-01T05:35:44Z")

</div>

from my understanding each shell instance has a unique set of environments.

If you run it under a bash script, when the shell ends after the script has run the variable dies with it

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [2 March 2021 04:34 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762/4 "2021-03-02T04:34:05Z")

</div>

I would put the command you want to run in the second exec node into the script you want to source and just launch that script in a single exec node. Keeps things self-contained

Environmental variables are not global, but they can look that way because a "standard" set is generally created in various .bashrc and/or .profile files that are highly system dependent and loaded when a new login shell is created and possibly a different or null set when a non-interactive (not attached to a "terminal") shell is launched.

I try to avoid using environmental variables whenever possible.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 May 2021 04:34 UTC](https://discourse.nodered.org/t/set-linux-shell-environment-variable/41762/5 "2021-05-01T04:34:16Z")

</div>

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