guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can system modify an environment variable in the current environment


From: Roel Janssen
Subject: Re: Can system modify an environment variable in the current environment?
Date: Thu, 02 Sep 2021 22:06:37 +0200
User-agent: Evolution 3.40.4 (3.40.4-1.fc34)

Dear Mortimer,

On Thu, 2021-09-02 at 15:49 -0400, Mortimer Cladwell wrote:
> Hi,
> 
> Consider my file test.scm:
> 
> (define (main args)
>   (let* ((myvar (string-append "export
> GUILE_LOAD_PATH=/some/random/text:$GUILE_LOAD_PATH"))
>            (statement1 (system (string-append "echo " myvar " >>
> $HOME/.bashrc")))
>             (statement2 (system myvar)))
>     (write myvar)))
> 
> At the terminal:
> 
> mbc@HP8300:~/temp$ echo $GUILE_LOAD_PATH
> /home/mbc/.guix-profile/share/guile/site/3.0
> 
> mbc@HP8300:~/temp$ guile -e main -s test.scm
> "export GUILE_LOAD_PATH=/some/random/text:$GUILE_LOAD_PATH"
> 
> mbc@HP8300:~/temp$ echo $GUILE_LOAD_PATH
> /home/mbc/.guix-profile/share/guile/site/3.0
> 
> At the end of .bashrc I see the last line is:
> 
> export
> GUILE_LOAD_PATH=/some/random/text:/home/mbc/.guix-
> profile/share/guile/site/3.0
> 
> If I close and reopen the terminal and:
> 
> mbc@HP8300:~$ echo $GUILE_LOAD_PATH
> /some/random/text:/home/mbc/.guix-profile/share/guile/site/3.0
> 
> So statement1 works as expected, modifying .bashrc which is then
> effective
> in modifying GUILE_LOAD_PATH on future invocations of terminal.
> 
> statement2 is an attempt to modify the current running environment, but
> fails.
> Note that if I paste export
> GUILE_LOAD_PATH=/some/random/text:$GUILE_LOAD_PATH directly into the
> terminal, that successfully modifies the variable.
> 
> Why does  (system myvar) i.e. (system "export
> GUILE_LOAD_PATH=/some/random/text:$GUILE_LOAD_PATH") fail?
> 

The "system" call executes in a separate environment which is exited
when the call finishes.

Instead you want to use the "setenv" procedure instead:
(setenv "GUILE_LOAD_PATH" (string-append "/some/random/text:" (getenv
"GUILE_LOAD_PATH")))

Or in this particular case, use the "add-to-load-path" procedure:
https://www.gnu.org/software/guile/manual/html_node/Load-Paths.html



Kind regards,
Roel Janssen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]