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.

  • 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 8 '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 8 '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 8 '17 at 16:43
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.

  • Is it possible to read HISTFILE somehow or do I have to set it manually ? – bertfred Mar 8 '17 at 19:16
  • 2
    Try (shell-command-to-string "bash -ic 'echo $HISTFILE' 2>/dev/null") – politza Mar 8 '17 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.