turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Environmental variables example missing in tutorial

Open codygman opened this issue 10 years ago • 7 comments
trafficstars

Maybe I just didn't notice it, but in my opinion this is a must have for anyone writing shell scripts. I know I can use System.Environment, perhaps Turtle should consider re-exporting it (or maybe only lookupEnv as getEnv)?

codygman avatar Jan 30 '15 23:01 codygman

I actually do provide environment variable utilities, but only for more recent versions of base. See here, specifically export, unset and need:

https://github.com/Gabriel439/Haskell-Turtle-Library/blob/master/src/Turtle/Prelude.hs#L104

I depend on base to provide platform-agnostic environment variable manipulation, which is why older versions of base don't support those utilities.

The tutorial doesn't mention them yet because they are not supported in ghc-7.4 (which is what Debian stable uses). Once Debian stable has a newer version of ghc then I will more publicly advertise those utilities.

Gabriella439 avatar Jan 30 '15 23:01 Gabriella439

Does this solve your issue?

Gabriella439 avatar Feb 03 '15 03:02 Gabriella439

Current Debian stable uses ghc-7.6.3: https://packages.debian.org/stable/ghc

int-index avatar Jun 27 '15 16:06 int-index

@Gabriel439, I would say that we're missing a pure option of using the environment vars, as follows:

[nix-shell:~/src/iohk]$ echo $FOO

[nix-shell:~/src/iohk]$ FOO=1 bash -c 'echo $FOO'
1
[nix-shell:~/src/iohk]$ echo $FOO

..which only sets FOO in the scope of the subprocess.

Should I file a separate issue for that?

deepfire avatar Jun 20 '17 16:06 deepfire

@deepfire: You can do this indirectly using the subprocess runners that take a CreateProcess as an argument, such as Turtle.Prelude.system and Turtle.Prelude.stream. The CreateProcess record provides an env field that lets you specify a temporary environment to pass to the subprocess

Gabriella439 avatar Jun 22 '17 16:06 Gabriella439

@Gabriel439, strictly speaking you're right -- but do you also think that this is a bit cumbersome, and desirable to be improved?

deepfire avatar Jun 27 '17 15:06 deepfire

The main issue is that adding support for this would double the already high number of subprocess runners in the API. It's also not clear that it would significantly improve on the CreateProcess-based API

Gabriella439 avatar Jun 27 '17 15:06 Gabriella439