Environment Variables in Racket
Our program demonstrates how to work with environment variables in Racket. Environment variables are a universal mechanism for conveying configuration information to programs. Let’s look at how to set, get, and list environment variables.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is not defined.
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up.
In Racket, we use putenv
to set environment variables and getenv
to retrieve them. The environment-variables-names
function gives us a list of all environment variable names. Unlike Go, Racket doesn’t provide a direct equivalent to os.Environ()
that returns both keys and values, so we’ve focused on printing just the keys in this example.