# Variables and includes

**URL:** <https://www.ruby-forum.com/t/variables-and-includes/225523>\
**Category:** NGINX\
**Created:** [January 13, 2013, 6:41am UTC](https://www.ruby-forum.com/t/variables-and-includes/225523 "2013-01-13T06:41:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [January 13, 2013, 6:41am UTC](https://www.ruby-forum.com/t/variables-and-includes/225523/1 "2013-01-13T06:41:17Z")

</div>

Is it possible to use a variable from one configuration in a included  
config file? Example:

set $a = “hello”;  
include test.conf;

[test.conf]  
if ($a = “hello”) {  
set $a = “world”;  
}

# something that works with $a

## Within the scope of the commands of test.conf, will $a be “hello” or “world”? Currently my usage like this gives me a, “using unitialized variable” warning.

Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_LSMiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c4cdca/32.png) [@Daniel\_LSMiller](https://www.ruby-forum.com/u/Daniel_LSMiller)\
**Post date:** [January 14, 2013, 3:51am UTC](https://www.ruby-forum.com/t/variables-and-includes/225523/2 "2013-01-14T03:51:19Z")

</div>

Hello!

On Sat, Jan 12, 2013 at 09:40:14PM -0800, Daniel L. Miller wrote:

> # something that works with $a
> 
> Within the scope of the commands of test.conf, will $a be “hello” or  
> “world”? Currently my usage like this gives me a, “using  
> unitialized variable” warning.

The “include” directive works during configuration parsing and  
completely transparent to everything else. That is, you may set a  
variable in one file and then use it in an included file, it is  
expected to work fine.

On the other hand, example you’ve provided is syntactically  
invalid and will result in the following error during  
configuration parsing:

nginx: [emerg] invalid number of arguments in “set” directive in …

Correct way to write it would be

set $a “hello”;

Note there is no “=” character. See [Module ngx\_http\_rewrite\_module](http://nginx.org/r/set) for  
details.

Note well, that after fixing the example the $a at the end of  
test.conf will be either “world” (if test.conf goes after ‘set $a  
“hello”;’) or uninitialized if it’s included somewhere else.

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![Daniel\_LSMiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c4cdca/32.png) [@Daniel\_LSMiller](https://www.ruby-forum.com/u/Daniel_LSMiller)\
**Post date:** [January 14, 2013, 5:18am UTC](https://www.ruby-forum.com/t/variables-and-includes/225523/3 "2013-01-14T05:18:56Z")

</div>

On 1/13/2013 6:50 PM, Maxim D. wrote:

> > [test.conf]  
> > variable in one file and then use it in an included file, it is  
> > set $a “hello”;
> 
> Note there is no “=” character. See [Module ngx\_http\_rewrite\_module](http://nginx.org/r/set) for  
> details.  
> Shows what happens when you quickly type up an example…thanks for  
> catching it.

So I repeat my question - why, given the above example (with correct  
syntax), would I see warnings for “uninitialized variable” for the above  
in the “test.conf”, as the variable is declared prior to the include  
statement?

–  
Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_LSMiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c4cdca/32.png) [@Daniel\_LSMiller](https://www.ruby-forum.com/u/Daniel_LSMiller)\
**Post date:** [January 14, 2013, 12:10pm UTC](https://www.ruby-forum.com/t/variables-and-includes/225523/4 "2013-01-14T12:10:08Z")

</div>

Hello!

On Sun, Jan 13, 2013 at 08:18:35PM -0800, Daniel L. Miller wrote:

> > > 
> > 
> > completely transparent to everything else. That is, you may set a
> 
> include statement?  
> Because of another problem resulted from quick typing? Show the  
> exact configuration which produces warning for you.

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
