Solved: How to get OS environment variables in Crystal

How to get e.g. the Linux $USER environment variable in Crystal?
Equivalent to ENV['USER'] in Ruby

ENV["USER"]

https://crystal-lang.org/api/ENV.html

1 Like

Note that in Crystal single quotes are used for chars.

String literals accept a number of different delimiters, but not single quotes.

1 Like

Oeps… how simple it can be, I also started to write my strings in python between double quotes, completely overlooked this :frowning:
@Blacksmoke16 and @fxn, thanks for your reply!

Unrelated, but I think ‘a’ being allowed is super confusing to beginners. I’d suggesting forcing it to be more explicit like ‘a’.to_c or “a”.to_c (is allowed, and only that syntax is allowed, and checked by the compiler, and ‘a’ is not allowed). Though I know I’m late to the party :slight_smile:

1 Like