From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: emacs doesn't inherit PATH from environment Date: Wed, 14 Feb 2018 19:38:42 -0700 Message-ID: <20180214190011968486164@bob.proulx.com> References: <874lmjma7g.fsf@robertthorpeconsulting.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1518662254 12380 195.159.176.226 (15 Feb 2018 02:37:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Feb 2018 02:37:34 +0000 (UTC) User-Agent: Mutt/1.9.3 (2018-01-21) Cc: help-gnu-emacs@gnu.org To: Larry Evans Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Feb 15 03:37:30 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1em9QJ-0002XT-Ca for geh-help-gnu-emacs@m.gmane.org; Thu, 15 Feb 2018 03:37:23 +0100 Original-Received: from localhost ([::1]:57464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em9SL-0004nL-3n for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Feb 2018 21:39:29 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em9Rg-0004n3-3i for help-gnu-emacs@gnu.org; Wed, 14 Feb 2018 21:38:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1em9Rc-00050c-VB for help-gnu-emacs@gnu.org; Wed, 14 Feb 2018 21:38:48 -0500 Original-Received: from havoc.proulx.com ([96.88.95.61]:35199) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1em9Rc-0004yy-NC for help-gnu-emacs@gnu.org; Wed, 14 Feb 2018 21:38:44 -0500 Original-Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 8E6DC179A; Wed, 14 Feb 2018 19:38:43 -0700 (MST) Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 528B921241; Wed, 14 Feb 2018 19:38:43 -0700 (MST) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id 21D4C2DC6B; Wed, 14 Feb 2018 19:38:42 -0700 (MST) Mail-Followup-To: Larry Evans , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 96.88.95.61 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116014 Archived-At: Larry Evans wrote: > I understand, and after changing ; to : in ~/.emacs.d/init.common.el > it worked; however, the point I was making is the setting of PATH > in ~/.emacs.d/init.common.el shouldn't be needed. I agree. Why are doing it? :-) > Indeed, the setenv in ~/.emacs.d/init.common.el was deleted, but I > also moved the 'export PATH' from ~/.bashrc to ~/.profile. After > that, the Makefile worked. Sounds good. In my world view the best and only place to set PATH is in the .profile and not elsewhere. So glad to hear from you that things are working in the normal configuration. That's great. > The conclusion I reached was that somehow emacs, when invoked from > my windows interface, apparently just runs the ~/.profile code but > not the ~./bashrc code and that's why emacs was not seeing the PATH > (because, previously it was set in ~/.bashrc). I have no idea about MS-Windows but in the Unix/GNU universe the environment used to be simple. In the simple days when logging in the shell would look at it's own name and see that it started with a "-" such as "-bash" and know that it was being communicated to by /bin/login that it was a login shell and should source the login environment files as a login shell should do. That means ~/.profile for Bourne derived shells. (And there is no need to discuss csh derived shells, becuase it is csh and no one should be using it anymore. Regardless that I know many are still using it.) Then in the .profile a bash user would then detect that they are running bash and if so then source the ~/.bashrc file explicitly. If it is not done explicitly then it is not done at all. You are in control. However I can't think of a reason not to source it there. if [ -n "$BASH_VERSION" ]; then . "$HOME/.bashrc" fi And of course a bash only user might decide to use ~/.bash_profile instead. If so then of course only bash reads that file and so no test to check for running bash is needed and one can simply source the ~/.bashrc file unconditionally. In a ~/.bash_profile file: . "$HOME/.bashrc" Note that if you have a .bash_profile then it *overrides* any further bash use of ~/.profile. Which can frustrate you terribly if 'rvm' decided to create it for you and you didn't realize it did that and are trying to figure out where things went wrong. I hate rvm for this reason. It makes bad assumptions and breaks things. But I digress. Personally I still use a ~/.profile and keep it generic. Because that allows me to switch around and use ksh and zsh and still get a sane environment shared among all of them. I put PATH only in .profile and use ~/.bashrc for bash specific settings such as HISTCONTROL and PS1 and "shopt -s checkwinsize" and so forth. Or by environment variables that I might want to change from one shell invocation to the next. This is why ~/.profile is the natural place for PATH. So that even if one switches shells that PATH will still be set as desired. Since PATH is not a shell specific item. However, and this is a big *HOWEVER*, along came Desktop Environments such as GNOME, KDE, LXDE, XFCE, and others running an "xdm" or X Display Manager such as lightdm and others. For some reason unfathomable to me they decided not to set up the originating shell as a login shell! That is really a shock to me. And one that has caused problems for literally decades. Instead it is distribution defined behavior what happens when an xdm such as lightdm starts. It might do one thing or it might do another thing but you can count on it NOT sourcing your ~/.profile! Instead most distributions will cause it to source a ~/.xsessionrc file. On my Debian system that is sourced from the /etc/X11/Xsession script by the /bin/sh shell and therefore cannot contain any bash specific features. It should contain only portable shell constructs. Setting PATH and other variables is okay. IMNHO the only sane thing to do in the ~/.xsessionrc file is to source the $HOME/.profile file. They are both portable shell syntax files. Then put all of your environment setting in ~/.profile the same as always. Otherwise one ends up with some things set one way when logging in with ssh and some things set another way when logging in with a graphical login manager. In ~/.xsessionrc file: . "$HOME/.profile" [[There is also the ~/.xsession script. I used to use and recommend that way for years. But I have been convinced by others that it is better to recommend the ~/.xsessionrc file instead. It is less for people to understand using that file.]] That covers almost everything. Unfortunately there is the traditional 'rsh' implemented by the current 'ssh' and shell environment. It's yet again a few special cases. But not relevant here so skipping discussing it. I realize that all of this might be foreign concepts to an MS-Windows user. But that is why I wrote it. So that it would become more familiar and hopefully help people understand how things work. And perhaps people using Unix/GNU might enjoy reading it too. :-) Bob