gregwebs / Shelly.hs

Haskell shell scripting
BSD 3-Clause "New" or "Revised" License
418 stars 88 forks source link

How to set the PATH variable? #38

Closed gdetrez closed 11 years ago

gdetrez commented 11 years ago

I gathered from the future plans that there is a problem with the way $PATH is handled. I'd like to know if the problem only concerns shelly which implementation or if appendToPath should be avoided completely?

I tried the following code:

absPath ( "dist"</>"build"</>"bnfc") >>= appendToPath
which "bnfc" >>= inspect
cmd "which" "bnfc"
cmd "env"
cmd "bnfc"

and the result is puzzling me: Shelly.which returns Nothing (which, if I understood correctly is expected) but although the path in cmd "env" is corect and cmd "which" "bnfc" print the expected result, cmd "bnfc" still returns exit status 127 (command does not exists)

Is there a workaround for this? I tried cmd "export" ... but then it can't find the export command.

gregwebs commented 11 years ago

I think export is a shell built in. this issue is documented on the run function, or do you find the documentation confusing? cmd is just a nicer api that uses run.

There is a way to set env variables in the command that you run though, at least with escaping set to False using the prefix env variable form

VAR=val command

gdetrez commented 11 years ago

I think export is a shell built in. this issue is documented on the run function, or do you find the documentation confusing? cmd is just a nicer api that uses run.

I see it now. I did't look at run, sorry :-/

There is a way to set env variables in the command that you run though, at least with escaping set to False using the prefix env variable form

I guess this wouldn't solve my problem anyway because the environment variable seem ta be set correctly already.

Thanks for your answer

gdetrez commented 11 years ago

In case someone else have the same problem, I found an easy workaround: instead of calling cmd "bnfc", I used cmd "env" "bnfc". It works fine with shelly's appendToPath method!

gregwebs commented 11 years ago

that works because env is now launching a new command znc the PATH was already set for the environment that env is in.. sh -c would probably work also. But the upcoming 1.0 version will work unless escaping False is set. I could use env for escaping False but it won't work on Windows, so I think I will just document the env trick