Hello, everybody
Is it possible somehow to unset (remove) environment variable after it was set with Unix.putenv
? Maybe I miss something, but I do not see any suitable function for this task in Stdlib
Hello, everybody
Is it possible somehow to unset (remove) environment variable after it was set with Unix.putenv
? Maybe I miss something, but I do not see any suitable function for this task in Stdlib
Indeed, I believe this function does not exist in the standard library at the moment. It could be a nice addition.
Cheers,
Nicolas
unix
library. But maybe Iām missing something.execve
, but then, it seems thereās no way to get a full environment list either (?)Yeah, this seems like a real problem. Also, really easy to fix. Unless somebody else wants to just hack up a patch, Iāll do right now. Maybe Iāll learn that thereās an incompatibility issue I donāt understand. Hey, itāll be an adventure!
Oh, thereās Unix.environment()
which returns the environment, and then you can pass it to Unix.execve()
. I retract my previous comment.
ETA: I donāt mean to suggest that this is a solution to your problem, but rather, a workaround.
FWIW there is (among others) unsetenv in ExtUnix.
With the advent of OCaml 5.0, adding a thread-broken function to the standard library seems a bit short-sighted. In fact, it might be worth considering the removal of Unix.putenv
altogether.
The majority of uses of putenv
/unsetenv
can be adequately replaced by calls to execve
. The only use case that is not covered by execve
, as far as I know, is when you want to communicate with a linked library through the putenv
/getenv
covert channel.
And the use-case of getting times in different timezones by setting the TZ variable.
There was an attempt to add Unix.unsetenv
together with Unix.setenv
, but it was not merged because of concerns about the semantics of Unix.setenv
. IMO Unix.unsetenv
by itself should be uncontroversial.