From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.user Subject: Re: Can system modify an environment variable in the current environment? Date: Thu, 2 Sep 2021 22:09:15 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28662"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 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:09:39 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 1mLt1m-0007DV-1a for guile-user@m.gmane-mx.org; Thu, 02 Sep 2021 22:09:38 +0200 Original-Received: from localhost ([::1]:37370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLt1k-0002ZQ-QA for guile-user@m.gmane-mx.org; Thu, 02 Sep 2021 16:09:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLt1U-0002Yo-UB for guile-user@gnu.org; Thu, 02 Sep 2021 16:09:20 -0400 Original-Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:36487) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mLt1T-0000QE-Bz for guile-user@gnu.org; Thu, 02 Sep 2021 16:09:20 -0400 Original-Received: by mail-wr1-x42d.google.com with SMTP id q14so4846209wrp.3 for ; Thu, 02 Sep 2021 13:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=LJ3elm2CCUHdLjdJE9j6xQ2YpqMlszIGOKQNbR77BDI=; b=ibc3f+OyG2mA7ivBzrVt0vBqBZPjxTUBOkWbEFSDrEC6N3i0/hxaBxTXs4VAHFotTU Ow5QS+/ZNmZ48TG01llUbZRkcKhU88F3IiVDs9HVknGFVAzIYonITYYv3esWkTCE7C4v aum1ZS+Tz4lRpU0qh+X7zmCC4JV9m/jWQ+P73pVqJo6zaNwB0gCF30jnwumaJgxVYVSH NBwkyDrX7MHsCPToELzZW1TU4/5Hqf0AprsjbZO3u6qcYlng/Dm7ljFxA9YcIMOFe3m+ ODrCv3miLSWf0cR492xjazEcCXpOf/mCGnaytYYLF4A0yuGPjmYybAYlWHE+hBzj8RGo LXTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LJ3elm2CCUHdLjdJE9j6xQ2YpqMlszIGOKQNbR77BDI=; b=Xhn7QwFegMyINzmelck4VMk5Ztkm9791u+M+0S4f6G1rj2Fb1PYn9eNC2Ux8juj98E wkj/GAabEfN/oAPZVD/rAUTQUtVJJkUN8AXF8XMj1pV+04R9WomOSSrNnXNNBfejzmnt gmgQLnVy+MV5sg9o8DMWIDcPOOSV2EelfiZ7FLHqI6NTYwHIL1gyOdEREyNH5BJLfRs8 9I2Ic4MyrPjRrEn2bMB+ZeY/YRoSnkzHcez6d5nL0sYI2TJOAdQa0Q6SBLNKYV+Bls91 ps4iIju6SSquV+/leWI74pSM3j2uDTslgsRV5WX33a1RR5KdlRX+jh+pl9ZZhaKY2kLC M/zA== X-Gm-Message-State: AOAM533RvrpuYkP5t6MTgDIyqSXNoSeyakKYNUhnAGF8uianY38YhkPR R36+jm4NfKx11ZQPo0r/mfCz5L8QQsU= X-Google-Smtp-Source: ABdhPJyBYUkatb1L1RPOHEfcsGFgG41VR4aveVGU8cqvOo8c6KnGQDIt0E3q7yHw/KUAaHbU5ZCOBw== X-Received: by 2002:adf:9e43:: with SMTP id v3mr48206wre.274.1630613356827; Thu, 02 Sep 2021 13:09:16 -0700 (PDT) Original-Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id e26sm2837183wrc.6.2021.09.02.13.09.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Sep 2021 13:09:16 -0700 (PDT) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=taylan.kammer@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-2.225, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:17707 Archived-At: On 02.09.2021 21:49, 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? > Thanks > Mortimer > Hi Mortimer, The "system" procedure starts a child-process in the operating system. In the Unix process model, the changes to the environment made by a child process do not affect the parent. Note that anything for which you use "system" above can be done directly within Guile by using the appropriate procedures, instead of starting a child process using the system shell. You might want to look for I/O related procedures to figure out how you can append text to an existing file. This might help: https://www.gnu.org/software/guile/manual/html_node/File-Ports.html Setting an environment variable is simple, just use 'setenv': https://www.gnu.org/software/guile/manual/html_node/Runtime-Environment.html Hope that helps. :-) -- Taylan