2

I'm trying to print the path of $HISTFILE in emacs, but it doesn't work with (getenv "HISTFILE") or (shell-command-to-string "echo $HISTFILE"). It is working with $PATH and every other variable I've tried.

bertfred
  • 1,729
  • 1
  • 12
  • 24
  • Maybe Emacs was started within a sh session. To check, just launch two terminals, one under bash, and the other under sh. In every of the two terminals, type: echo $HISTFILE. – Nsukami _ Mar 08 '17 at 14:05
  • .. or from a desktop environment that does not set HISTFILE, so it is not in emacs's environment. OTOH, if you start a shell within emacs with M-x shell it will set HISTFILE, so it will be in its environment (but still not in the environment of emacs). – NickD Mar 08 '17 at 15:24
  • why does my arch linux not set HISTFILE, though I can echo it ? And I just found out, that shell also tries (getenv "HISTFILE") and otherwise sets it with ...(string-equal shell "bash") "~/.bash_history")... – bertfred Mar 08 '17 at 16:43

1 Answers1

3

I'm assuming you're using the bash-shell. The HISTFILE environment variable is either set implicitly by the shell or by setting it in some script file, e.g. ~/.bashrc.

Emacs inherits the environment from the process that started it, which is usually some X-window-manager, while shell-command-to-string starts a non-interactive shell.

So, either there is no shell involved, or it is, but neither does it set this variable implicitly, nor does it read any initialization scripts, where it may have been set.

politza
  • 3,336
  • 16
  • 16