From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SFshCQWTTmAGIwAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 22:49:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id oODUBAWTTmCNLwAAB5/wlQ (envelope-from ) for ; Sun, 14 Mar 2021 22:49:41 +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 4908218C4B for ; Sun, 14 Mar 2021 23:49:40 +0100 (CET) Received: from localhost ([::1]:42248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLZYI-0001ya-E3 for larch@yhetil.org; Sun, 14 Mar 2021 18:49:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLZXg-0001yC-Ix for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 18:49:00 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:38875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLZXd-0001l1-7H for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 18:49:00 -0400 Received: by mail-pl1-x635.google.com with SMTP id s7so14368006plg.5 for ; Sun, 14 Mar 2021 15:48:56 -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=7G+n0CQWPkjutf1lWkLr7SuNYJCyyiEU2Df9iExAHyE=; b=g2SbIGzY3R6h/mWNNBkmcyiKy69VfQ6LdqEq2L7YwRluCIy/Wu69NO5bJtlb/JJDWH QZGSVuKHNQx8/eyGtqAUJB7b75CYzkMJ+OguReVx7Mb6xu9N16l0pwYJ083tFYfXwtL2 YbmR0uxvL811wu1snVoiWJEgRCXgqAcMUkD4LHVow0So1jxiz+lrdDyXitn3B20AcYLy SEFswcFAp27dpGj0W/PsmvvoAxEa7B6qQvTpq/ht7NP6w4cqZar5qjo3Bug7eEd0SCL/ PZGsPo0w0zBD/y6oAZOPY1DROzQS5ImSBV5LOSyND1QeKdCmR7KIktzTlpme8y7njf7O xGtg== 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=7G+n0CQWPkjutf1lWkLr7SuNYJCyyiEU2Df9iExAHyE=; b=hfv1b8fb8Nj0u4i6+JMvW7lTkY9qI9rvNeKo8CFetHPq7nl3Cy26NQXaQHZCmqy1jo tFU0KE9Ek/F+OxR/IP10ukU7bYMa1lzAyuOc8GTJK1zvJOG+x5IyXkfSQmvAtUucTU6g vZSFXFari8wBlz13J8jWtYnNZv4b9ecHWqdZt4+xwpgwK8MQxQ/ksNUo4Z81TEASfOde XnHY+Mq3qmGfcRizD+rybhF5RqjbR4nzqHzAxUr4HaLPWWhwNrYy0ZZIl83v8BlQkO2F VAmo6sFrWTGU9DIFcMDYR8UcjvViyUeLVR4rlUZKawVsi7j1cFTUXHbwVhMvUdp3QLPB G+fg== X-Gm-Message-State: AOAM5337KNsq9i8kTtAbvTIH3+48jWGQTY2EZg0KVjFTeOPxG/+c4Omx /nv3fPZUajVkiDqWK7x5C4zoYc/3OQs= X-Google-Smtp-Source: ABdhPJxGlJgoAFbfq0BV7OmrJG3LxkHfPQPbAywOC/FvGczuTVRFXKtTV3gwMAnxQG/1dm4vQ/ZFQQ== X-Received: by 2002:a17:90a:8913:: with SMTP id u19mr9544644pjn.59.1615762134666; Sun, 14 Mar 2021 15:48:54 -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 j35sm11830684pgj.45.2021.03.14.15.48.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 15:48:54 -0700 (PDT) References: 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 08:51:57 +1100 In-reply-to: Message-ID: <87a6r5l5bh.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=theophilusx@gmail.com; helo=mail-pl1-x635.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=1615762180; 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=7G+n0CQWPkjutf1lWkLr7SuNYJCyyiEU2Df9iExAHyE=; b=jCsd5eqeEV5qkMcLGE6/qAj9H8LmwZEYsCtfeRCFEIz6T1C07PYR6R1i98TzfFt4SgNl/I dddoNIPiPLZEzOgL9bXP7FeGcIlHAXVnWfoRcniZBhU075NmZqdXHrM+MwLgTTXwbNqNVZ Rgk2gXILsxt4hnBdgvrb4tX6zIT63c4rlHfkPFGacHq+8pYdYblf+QynSUkvTCsUyzep4T 1eh/mDJ8Y/Wx5xFQnzARzYPKgtFVQMGRomzoRmksTrrgwlTzKCOzuHt9KkcB3pI9Icz0PQ uTXCO5zu+plpONy/xmOymFdC9/RF1LLDI3lAQFzrqqC7/SrlvSm7lB4/mgrqjQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615762180; a=rsa-sha256; cv=none; b=hxDe86Q85v5eNzFqjyb1uXQFExirM1p4ys9djTWBC849wD49RYI0rWAE00WWCrdH0mApKf qsEkP1k/wKlBT26eWX1zy27J5l6nx4lgrGc7ld50YepPobfmWxG0pT5wTKtGIcCRIMBaEO +uNdHcqJ5TM/wHFe7jt68x3Y2EWFK3GtMEhQxCTEeWNt0oGH5cUBNY/m5Hjf5DSI5vo1A8 iSnHvcjCma1eGkN3yMHw+e5jbLVX2UobynnX4G0/QVPH2ECqkJMO3yE5JeXvEJmfEXL54T qC5eC4VpvbNNaNvBGWgTPYdcUZ28Q3+Gj5HOgL8BBZGYzLqbC+e7V7qcEgQIFA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=g2SbIGzY; 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=g2SbIGzY; 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: 4908218C4B X-Spam-Score: -2.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: vN6GJdxB+KjB Is this perhaps on a Mac where Emacs is started from the dock? If so, it could be because on the mac, applications started from the dock are not executed inside a login shell. Do you get different results if you start emacs from within a terminal? If so, this is almost certainly the source of your issue/difference. I am also a little confused by your examples. Some of them are attempting to source .bash_profile, others .bashrc and others .zshrc. Which shell are you using and which files do you have? I get the feeling that in your frustration, you have taken a 'shotgun' approach and added the variable everywhere. It might be time to go back and look at all your shell environment files and rationalise them a bit. Things can become a little confusing when running zsh as so many things assume/expect a bash shell. While zsh is pretty compatible with bash, so few problems arise, it can lead to confusion regarding where to set variables and understand what is being sourced and when. For some reason, there seems to be some confusion these days about the difference between .profile, .bash_profile, .bashrc, .zsh_profile and .zshrc. In particular, I frequently see incorrect/wrong advice regarding the use of 'profile' and 'rc' files. Most of it can be blamed on wrong advice in forums like stack overflow! The 'profile' and the 'rc' files fulfil different purposes and are sourced at different times. Have a careful read of the bash man page (even if your running zsh as they all tend to follow the same pattern). I would also experiment with just dumping out the output of 'env' and not run it through grep so that you can see what is being defined. This can help you understand what is being sourced. I also think it is a good idea to be explicit about the shell so that you have more control/understanding over what is being run e.g. put the line #!/bin/bash or #!/bin/zsh or #!/bin/sh as the first line. In very broad terms (glossing over some of the subtleties, which is likely the cause of some of your issues), the 'profile' files are only sourced for login shells and the 'rc' files are sourced whenever a new shell process is run. Note that these processes run in a hierarchy i.e. shell processes have a parent process. Some things have to be set in your 'profile' (or are better set there) while other things must be set in your 'rc' file. For example, setting PATH in your 'profile' is normal because you typically just want that set once and then 'exported' to all child processes. Setting a dynamic prompt which changes depending on the directory your in (or because it has some other dynamic data, like the time) need to be set in your 'rc' file because these are sourced before each shell process is executed. I the 'old days' it was important to get these distinctions correct because sourcing the files could have a performance impact - not as big an issue these days. These days, things seem to have become even more confusing in an attempt to make things easier. I often see people with a .profile, a .bash_profile, a .bashrc, a .zsh_profile and a .zshrc with variables set and exported mixed in across all these files. This is a source of terrible confusion and unexpected results. Some 'canned' shell configurations, like 'oh-my-zsh' also try to be extra helpful by sourcing files which are not normally sourced by that shell (to make smoother migration from bash shells for example). Sometimes, it can be helpful to put a line like the following into each of these files echo "Executing at `date`" >> ~/profile.log just to see what is getting executed when (you won't want to leave this there - just for diagnostic and experimentation to help understand when things are being sourced. You could even dump out the output of 'env' so that you can see how the environment is being changed as each of these files executes. George Mauer writes: > I am confused why no matter how I try to run shell commands they seem to be missing variables exported in profiles. > > I have added 3 variables to various startup scripts > > - ~./bash-profile~ :: ~export GIM_BASH_PROFILE="yes"~ > - ~./bashrc~ :: ~export GIM_BASHRC="yes"~ > - ~./zshrc~ :: ~export GIM_ZSHRC="yes"~ > > I am running emacs in GUI mode so I get why none of these are available *directly* in emacs, so then I try > > #+begin_src shell :results list > env | grep GIM > #+end_src > > #+RESULTS: > > Ok that's kinda surprising, but I suppose it could be running ~/bin/zsh~ (that's my ~shell-file-name~) directly > > what about > > #+begin_src shell :results list > bash -c env | grep GIM > #+end_src > > #+RESULTS: > > That's pretty surprising. I would have expected running it directly to actually run my profile. > > Shockingly > > #+begin_src shell :results list > bash --rcfile ~/.bashrc -c env | grep GIM > #+end_src > > #+RESULTS: > > That is *still* nothing! > > Sanity is restored slightly when I run > > #+begin_src shell :results list > bash --login -c env | grep GIM > #+end_src > > which *does* indeed visit ~.bash_profile~ but only slightly. > > What is going on, and is there a straightforward way in which I can get shell block to read from a profile? -- Tim Cross