From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id eNK1E/rcTmArWAAA0tVLHw (envelope-from ) for ; Mon, 15 Mar 2021 04:05:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id Y1l8D/rcTmD8dAAA1q6Kng (envelope-from ) for ; Mon, 15 Mar 2021 04:05:14 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 814DF2A4A4 for ; Mon, 15 Mar 2021 05:05:13 +0100 (CET) Received: from localhost ([::1]:37862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLeTe-0006H5-Om for larch@yhetil.org; Mon, 15 Mar 2021 00:05:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLeTF-0006Gy-OG for emacs-orgmode@gnu.org; Mon, 15 Mar 2021 00:04:45 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:53980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLeTD-0006Cb-C1 for emacs-orgmode@gnu.org; Mon, 15 Mar 2021 00:04:45 -0400 Received: by mail-pj1-x1032.google.com with SMTP id t18so8058004pjs.3 for ; Sun, 14 Mar 2021 21:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:date:in-reply-to:message-id :mime-version; bh=ocUUmgJQpUH8D1O4TckBOyf65gXK589zQv8QfJmJ1K0=; b=ebR1o4EAheTfPOge1NZwxts0z/VU2VjoATif3XkdXoXl0NguPDx+AakmB9dnNWRaZF rooAct6EGqOEf2FJs4yLby154XAIMaBvpjR87MWtzWuWBZCBXeqWsUQbgDMZ9QHn3UR6 TcspX5vjrbWcnbesnzNU7XEhsHZa6xz+wKp+bF7BytPLnJhjlIDU2atCo1VzNT/6iugA jrt+xwdqGDzfyA9QCIh3pGMLnH9ljA8+YV3OimoGKg3J+ZJ9uIxHF2kNQ7+ET10zO7Yg 9vzghNEJmDMY1Mwrdnn7diOal41qrNfZUL9FYL7JJyfz++vhivPSzoAQ4mGHPFlY6qFW vklA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject:date :in-reply-to:message-id:mime-version; bh=ocUUmgJQpUH8D1O4TckBOyf65gXK589zQv8QfJmJ1K0=; b=J5br+fd8tMxspThSO9RXI3eFGe545LKZGCdISb7om2ycndKbv2pWMRdAEwXRAzRes5 gFsLoS0CIUREern8QgD38wbDX8/j8N+HYdf3J+B24+N0MyKU+wtt8tCYbeqc8Lyvo3K1 lIrQ1BK8lVwrAvdlEBZApSE4SVoogJFGkCZmxupeY6dS4qxEuQ4gPjfxzmaNMQsV8+Wn bqHaskdjRC7hpcFbKmPr6WGun2laaUhjVe3r0kJ+SAcqbFWKzmgkbf39m3c00VJ+SNLq qSBdA4G2nzPFLiG9RFx9jQgCTRDYIdc8DARaWSpioAxQvck+LvPWKrBlDw5Rccji2nZS fRRw== X-Gm-Message-State: AOAM533JxhuXz94ZOv2Tpxsgou4TV109IuqjX2k1EKUiK5FIb7QiKzBz aRZsp9j3x0DX1mGgqupwxFONL+o6iVg= X-Google-Smtp-Source: ABdhPJxYuK+oXLx1iluX2A04ilTXiFHjRl475REbFYWnZckIFr29YzJAcNX2Hm7I/Ig/A34KsX+pcw== X-Received: by 2002:a17:90a:ff91:: with SMTP id hf17mr11026819pjb.34.1615781081400; Sun, 14 Mar 2021 21:04:41 -0700 (PDT) Received: from tim-desktop (220-235-6-229.dyn.iinet.net.au. [220.235.6.229]) by smtp.gmail.com with ESMTPSA id g21sm8610975pjl.28.2021.03.14.21.04.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 21:04:41 -0700 (PDT) References: <87a6r5l5bh.fsf@gmail.com> User-agent: mu4e 1.5.10; emacs 27.1.91 From: Tim Cross To: emacs-orgmode@gnu.org Subject: Re: How to get shell source blocks to read my profile? Date: Mon, 15 Mar 2021 14:02:04 +1100 In-reply-to: Message-ID: <87ft0x2hbe.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=theophilusx@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615781113; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ocUUmgJQpUH8D1O4TckBOyf65gXK589zQv8QfJmJ1K0=; b=M6mPKl1cOJOOHjZyOojl57M9RNV9X8YyDmHl1SARKRnNGr/qLmiDnx2NXqw+M3+mUH4PLK J2J5/JtJwavTogkRCiP1D+9wgRNb9Zj+NsXHZxUjAUFiUtoyjnIZNYvDDRStsyp8tafbJn QfYVd8cV/VYKttPtQFcPlH0FXXSAnVeS19rD2uBIb6vhTpL2NCR+BCTi8ATIC7XwotiKQK iOlNFGdv/joMcyBfQFdCmovBrMF3tMDUO+ygph5e+R4FhC7jPU6emy56ai4G94fxGwhzi4 7WTgIZRW9SrS/EotQTvXRs5v/8Nr1AHQ0nXHIKOJSK49s+Lu2KjO0gpkuWZcNA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615781113; a=rsa-sha256; cv=none; b=GlX6auUQY04eGe7ztsK9DRrc3IQWFUhuBGkLcz/d4L8JA734Y/tlfOnc9Ox3V5+a59ze/p 6m2Brfw5BeUuNzmYkAvwqiQlctk3ludqJzl760eQevLpD5Fhkigqleh8WCTE9FTYMqzhKf WyyhoCCWoLqUAYUz9YDCov4Kwn16BjOAXNBDexjuUQTg4RtvlKd96por9GIYXjlW54HgIc CZW9I5rVU7m/HnEILJ6HQgJpyRaaZ/G+/eI9042m62QRkPeudxCMZ92fHvSeW5JXUFvHCq JPhMuuiU055sq6QM3ITnmloPNOSURbxDyXLfZkBQ202hMtKZX3PBQrZ9k9Tukw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ebR1o4EA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.10 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ebR1o4EA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 814DF2A4A4 X-Spam-Score: -2.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7j9DBiuP54wo comments in-line ... George Mauer writes: > Hey Tim, thanks for helping out. I commented inline to your response below but I'll sum up and ask the outstanding questions more directly here as well. > > I think you might have misread what I was doing - I had 3 different variables set in 3 different places precisely because I want to dissect things and figure > out which profile/rc scripts were run. > > Yes, this is emacs running in GUI mode so yes, it doesn't have a shell as a parent. But that only explains why these environment variables aren't in > emacs itself, not the spawned bash or zsh processes > To clarify, the GUI mode is unrelated. You can run in GUI mode from a terminal and the emacs process will inherit the environment in the terminal. If that terminal is a login terminal (i.e. terminal shell was run as a login shell), the 'profile' file will be sourced and the 'rc' file will have been sourced. If not a login shell, only the rc file will have been sourced. If on the other hand, Emacs is started from the dock, it is started in a completely different process chain and is not a child of a login process. This is why, if you want your emacs to have /usr/local/bin in the path, you have to add it to /etc/paths or /etc/path.d whereas if you start emacs from within a terminal (GUI or text mode), you only need to add /usr/local/bin to your PATH setting in .profile (just an example to highlight the difference between running from in a terminal and running from the dock). > So to sum up the specific questions. My ~shell-file-name~ is ~/bin/zsh~ which seems to be what ~ob-shell~ is passing down to be run. So why on earth > does my ~GIM_ZSHRC~ variable not show up here? > > #+begin_src shell > env > #+end_src > > When I actually directly call bash > > #+begin_src shell > bash -c env > #+end_src > Have a closer look on the section in the bash manual on the difference between interactive and non-interactive shells. (also holds for zsh). Basically, the 'rc' files are not sourced for non-interactive shells. > Why would the output not include ~GIM_BASHRC~ - it should have been run, right? > No. Adding the -c means it is a non-interactive shell, so no .bashrc sourcing. > What about when I call this? Even with explicitly selecting the rc file to run, it seems to not > > #+begin_src shell > bash --rcfile ~/.bashrc -c env > #+end_src > Same issue here. --rcfile only has effect in interactive shells. > Finally, the outstanding question about ~ob-shell~ is if there is any way to force it to run the shell processes' rc-script? I really would have expected it to > be run in the above situations already... > You could try sourcing it e.g. #+begin_src shell source ~/.bashrc env #+end_src or use 'shorthand' dot #+begin_src shell . ~/.bashrc env #+end_src there are also some options you can add at the 'shebang' line i.e. #!/bin/bash -l or #!/bin/bash -i which will change the behaviour. There is a lot of 'meat' in the bash man page and there is a lot of additional information in the bash info pages. However, both can be a bit terse and because the info is very 'dense', it is very easy to miss key points. In order to have environment variables available inside your org source blocks, you really need to - have them in the environment inherited by emacs when it starts. This will depend how you start Emacs (i.e from within an interactive shell vs from the dock). Note that you typically don't see this issue under Linux because in most Linux setups, the X environment is started inside a login shell. So everything started as part of the X session, like a dock, is a child of the login process and therefore inherits the login environment. On a mac, the dock is not part of the login shell, so it only inherits what is in the system wide bash profile file. - Ensure your source block run as interactive and/or login shells using shebang options like -i or -l - explicitly source the .profile or .bashrc file using a source call - pass the environment variable in on the command line e.g. #+begin_src shell FRED=barney env #+end_src will result in FRED=barney being in the output from 'env'. > ----------- > > Is this perhaps on a Mac where Emacs is started from the dock? > > Yup like I said, its in GUI mode so I understand why those environment variables aren't within emads itself > It is actually a little more subtle. It isn't because your running in GUI mode those variables are not there. It is because your running from the dock. Run it in GUI mode from within a login terminal and all those variables will be 'in' emacs. > It is certainly confusing but I think I got a handle on it mostly. If it's a login shell you'll run a profile, if it's not you'll run the default rc file unless one of the > options were specified. I think each is named specific to each shell name but oftentimes you chain them together in practice. > There is also a difference between interactive and non-interactive shells. I suspect this is the root cause of your issue. The source block being run are non-interactive. -- Tim Cross