# How to change the value of environment variable?

**URL:** <https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276>\
**Category:** Logstash\
**Created:** [August 30, 2016, 7:14am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276 "2016-08-30T07:14:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YYtea](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@YYtea](https://discuss.elastic.co/u/YYtea)\
**Post date:** [August 30, 2016, 7:14am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276/1 "2016-08-30T07:14:24Z")

</div>

```
input {
stdin{
	type => "${log_type:unknown}"
}
}

```

tried these and does not work  
ruby{  
code =\>"event.set('[@metadata][log\_type]','Atype')"  
}

```
ruby{
code =>"$log_type = 'Atype'"
}

```

using logstash 5.0.0-alpha4

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 30, 2016, 9:26am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276/2 "2016-08-30T09:26:28Z")

</div>

Why do you want to change an environment variable from inside Logstash? What's the underlying problem you want to solve, i.e. what you are trying to accomplish in the end?

---

<div class="post-metadata">

**Author:** ![YYtea](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@YYtea](https://discuss.elastic.co/u/YYtea)\
**Post date:** [August 30, 2016, 9:55am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276/3 "2016-08-30T09:55:42Z")

</div>

I am trying to archive auto detection on log type  
using existing patterns to test first 100 logs, which determine the log type it should use  
and then parse all the log

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 30, 2016, 11:31am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276/4 "2016-08-30T11:31:05Z")

</div>

I doubt `type => "${log_type:unknown}"` is evaluated for each message so even if you'd be able to change the environment it might not work, but if you want to try it out the Ruby code would probably be `ENV['log_type'] = 'Atype'`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:40am UTC](https://discuss.elastic.co/t/how-to-change-the-value-of-environment-variable/59276/5 "2017-07-06T04:40:56Z")

</div>


