How to add ENV variable in runhaskell shell script

Hi, In perl scripts (unix), one can do == #!/usr/local/bin/perl BEGIN { $ENV{LD_LIBRARY_PATH} = ...; } do my perl stuff == The setting of ENV variable before the program runs allows me to fix the shell environments. In this case, I need to specify where to look for the shared library. How do I do this in Haskell if I am writing the same script using: == #!/path/to/runhaskell {- how to set LD_LIBRARY_PATH = ... ? -} do my haskell stuff == Thanks, Steve

Hi,
On 1/14/08, Steve Lihn
In perl scripts (unix), one can do #!/usr/local/bin/perl BEGIN { $ENV{LD_LIBRARY_PATH} = ...; }
I've not tested this (what a great line to start a post...), but see if this works for you: #! /usr/bin/env LD_LIBRARY_PATH=/path/to/libs runhaskell which also has the (desirable? Hmm...) side effect of letting env figure out (using PATH) where to find runhaskell. This doesn't work for compiled binaries, sadly. Modifying LD_LIBRARY_PATH at runtime works for Perl because libraries are loaded at runtime, and the language allows you to sneak in some code before that happens. Even if Haskell had a System.Environment.withEnv (it already has a withArgs), it's probably too late to patch the environment -- you can't get in before the linker. (Unless you're using some sort of funky dynamic plugin thing.) Cheers, /Liyang

On Jan 13, 2008, at 23:16 , Liyang HU wrote:
On 1/14/08, Steve Lihn
wrote: In perl scripts (unix), one can do #!/usr/local/bin/perl BEGIN { $ENV{LD_LIBRARY_PATH} = ...; }
I've not tested this (what a great line to start a post...), but see if this works for you:
#! /usr/bin/env LD_LIBRARY_PATH=/path/to/libs runhaskell
Will probably work on Linux; many other (especially older) Unixlike systems will consider everything after the program name a single argument. Best bet is to use a wrapper script. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

only one argument is allowed after the #! on the first line. however the following should be portable if you must set the variable before runhaskell is executed: #!/bin/sh -- > /dev/null 2>&1; MYENV=foo runhaskell $_ import System.Environment main = getEnv "MYENV" >>= print -- John Meacham - ⑆repetae.net⑆john⑈

On 13/01/2008, Steve Lihn
Hi, In perl scripts (unix), one can do == #!/usr/local/bin/perl BEGIN { $ENV{LD_LIBRARY_PATH} = ...; } do my perl stuff == The setting of ENV variable before the program runs allows me to fix the shell environments. In this case, I need to specify where to look for the shared library.
How do I do this in Haskell if I am writing the same script using: == #!/path/to/runhaskell {- how to set LD_LIBRARY_PATH = ... ? -}
do my haskell stuff ==
Thanks, Steve
In System.Posix.Env there is a function setEnv which will let you set environment variables. I have no idea why this functionality is not exposed in System.Environment. - Cale
participants (5)
-
Brandon S. Allbery KF8NH
-
Cale Gibbard
-
John Meacham
-
Liyang HU
-
Steve Lihn