# How do I do this portably?

**URL:** <https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218>\
**Category:** Help & Support\
**Created:** [September 26, 2024, 9:17pm UTC](https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218 "2024-09-26T21:17:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralsina](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ralsina/32/2139_2.png) [@ralsina](https://forum.crystal-lang.org/u/ralsina)\
**Post date:** [September 26, 2024, 9:17pm UTC](https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218/1 "2024-09-26T21:17:56Z")

</div>

I am trying to selectively embed some files based on a list provided via an environment variable and a flag. This works in Linux and unix-like things, but it won’t work on Windows.

Any ideas on how to do this portably?

```crystal
  class LexerFiles
    extend BakedFileSystem

    macro bake_selected_lexers
      {% for lexer in `echo -n "$TT_LEXERS"`.split "," %}
      bake_file {{ lexer }}+".xml", {{ read_file "lexers/" + lexer + ".xml" }}
      {% end %}
    end

    {% if flag?(:nolexers) %}
      bake_selected_lexers
    {% else %}
      bake_folder "../lexers", __DIR__
    {% end %}
  end

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 26, 2024, 9:31pm UTC](https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218/2 "2024-09-26T21:31:14Z")

</div>

You can use [Crystal::Macros - Crystal 1.13.3](https://crystal-lang.org/api/Crystal/Macros.html#env(name):StringLiteral%7CNilLiteral-instance-method) to access the ENV var vs using the shell command which should make it more portable.

---

<div class="post-metadata">

**Author:** ![ralsina](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ralsina/32/2139_2.png) [@ralsina](https://forum.crystal-lang.org/u/ralsina)\
**Post date:** [September 26, 2024, 9:39pm UTC](https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218/3 "2024-09-26T21:39:34Z")

</div>

I _tried_ and failed :-D

I get

```auto
In src/lexer.cr:11:26

 11 | {% for lexer in ENV["TT_LEXERS"].split "," %}
                         ^
Error: undefined method '[]' for TypeNode of type ENV (must be a tuple or named tuple type)

```

---

<div class="post-metadata">

**Author:** ![jgaskins](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jgaskins/32/2449_2.png) [@jgaskins](https://forum.crystal-lang.org/u/jgaskins)\
**Post date:** [September 26, 2024, 9:45pm UTC](https://forum.crystal-lang.org/t/how-do-i-do-this-portably/7218/4 "2024-09-26T21:45:47Z")

</div>

In macros, you need to use the `env` macro method that @Blacksmoke16 linked to rather than the `ENV` constant.

```crystal
{% for lexer in env("TT_LEXERS").split "," %}

```
