From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Roel Janssen Newsgroups: gmane.lisp.guile.user Subject: Re: Can system modify an environment variable in the current environment? Date: Thu, 02 Sep 2021 22:06:37 +0200 Message-ID: <92defe0ebbea0cd329ab3bc80506c4a0e0923ea3.camel@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16681"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) To: Mortimer Cladwell , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Sep 02 22:07:06 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLszK-0004CM-14 for guile-user@m.gmane-mx.org; Thu, 02 Sep 2021 22:07:06 +0200 Original-Received: from localhost ([::1]:36142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLszI-0001XB-GD for guile-user@m.gmane-mx.org; Thu, 02 Sep 2021 16:07:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLsyv-0001Wn-1j for guile-user@gnu.org; Thu, 02 Sep 2021 16:06:41 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47624) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLsyu-0006dX-Hn; Thu, 02 Sep 2021 16:06:40 -0400 Original-Received: from 2001-1c02-0b16-3700-3718-3a46-b1ae-ba54.cable.dynamic.v6.ziggo.nl ([2001:1c02:b16:3700:3718:3a46:b1ae:ba54]:52024) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLsyu-000692-8n; Thu, 02 Sep 2021 16:06:40 -0400 In-Reply-To: X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17706 Archived-At: 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