# Setting Environmental Variables in Ruby script

**URL:** <https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001>\
**Category:** Ruby\
**Created:** [October 15, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001 "2008-10-15T19:06:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [October 15, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001/1 "2008-10-15T19:06:17Z")

</div>

I have a scipt that executes a shell command that requires my  
environment to be set so the script fails. Is there a way to add my  
profile settings into my ruby script?

Thanks

jack

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [October 15, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001/2 "2008-10-15T19:15:35Z")

</div>

jackster the jackle wrote:

> I have a scipt that executes a shell command that requires my  
> environment to be set so the script fails. Is there a way to add my  
> profile settings into my ruby script?

ENV[“varname”] = “value”

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [October 15, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001/3 "2008-10-15T19:29:08Z")

</div>

On Oct 15, 2008, at 11:06 AM, jackster the jackle wrote:

> I have a scipt that executes a shell command that requires my  
> environment to be set so the script fails. Is there a way to add my  
> profile settings into my ruby script?
> 
> Thanks
> 
> ## jack
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

cfp:~ \> cat this-is-a-bash-question.sh  
#! /bin/bash --login

echo $FOO

cfp:~ \> ./this-is-a-bash-question.sh

(nothing)

cfp:~ \> grep FOO .bash\_profile

(nothing)

cfp:~ \> echo ‘export FOO=42’ \>\> .bash\_profile

cfp:~ \> ./this-is-a-bash-question.sh  
42

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [October 15, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/setting-environmental-variables-in-ruby-script/151001/4 "2008-10-15T19:53:39Z")

</div>

Sebastian H. wrote:

> jackster the jackle wrote:
> 
> > I have a scipt that executes a shell command that requires my  
> > environment to be set so the script fails. Is there a way to add my  
> > profile settings into my ruby script?
> 
> ENV[“varname”] = “value”
> 
> HTH,  
> Sebastian

Thanks Sebastian…my ruby script takes all the variables without error  
but my script still fails so I must be missing something in my  
environment still. I’ll have to do some more checking…thanks again

jack
