bash 如何让emacs shell自动执行init文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/958194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make emacs shell execute init file automatically?
提问by polyglot
My bash init script (~/.profile) contains important initializations, but whenever I use shell-command or compile in emacs, that init file is not read, and without those initialization my bash commands in emacs will fail :( How do I force emacs to execute my init file for the shell that it's using for shell-command?
我的 bash init 脚本 (~/.profile) 包含重要的初始化,但是每当我使用 shell-command 或在 emacs 中编译时,init 文件不会被读取,如果没有这些初始化,我在 emacs 中的 bash 命令将失败:( 我如何强制emacs 为它用于 shell 命令的 shell 执行我的 init 文件?
Clarification: I'm not talking about M-x shell, which reads my init file just fine when I symlinked .profile to .emacs_bash.
澄清:我不是在谈论 Mx shell,当我将 .profile 符号链接到 .emacs_bash 时,它可以很好地读取我的 init 文件。
回答by Adam Rosenfield
Move your initialization routines into your ~/.bashrcfile
将您的初始化例程移动到您的~/.bashrc文件中
Then add the line
然后添加行
source ~/.bashrc
into your ~/.bash_profilefile. See the bash man pagefor a detailed explanation of which startup files get loaded when. The key is the difference between an interactiveand non-interactiveshell, as well as the difference between a loginand a non-loginshell.
进入你的~/.bash_profile档案。有关何时加载哪些启动文件的详细说明,请参阅bash 手册页。关键是一个之间的差交互和非交互一个之间的差值的外壳,以及登录和非登录壳。
In general, .bash_profileis run when logging into the system using a shell while .bashrcis run when starting a new shell (The OS X Terminal application is an exception to this rule as it runs .bash_profilefor each new terminal instance). For more info in article form, look here.
通常,.bash_profile在使用 shell 登录系统时.bashrc运行,而在启动新 shell 时运行(OS X 终端应用程序是此规则的一个例外,因为它.bash_profile为每个新终端实例运行)。有关文章形式的更多信息,请查看此处。
回答by Imskull
I'm using Mac, shell-command did not execute .bashrc, nor .bash_profile, I googled a solution to have my PATH problem fixed.
我使用的是 Mac,shell 命令没有执行 .bashrc,也没有执行 .bash_profile,我用谷歌搜索了一个解决方案来修复我的 PATH 问题。
put this in your .emacs: (setenv "PATH" (shell-command-to-string "source ~/.bashrc; echo -n $PATH"))
把它放在你的 .emacs 中: (setenv "PATH" (shell-command-to-string "source ~/.bashrc; echo -n $PATH"))
more detail, see: How to make emacs to run my ~/.bash_profile
更多详细信息,请参阅:如何使 emacs 运行我的 ~/.bash_profile
回答by polyglot
Digging through the elisp source; seems like the shell-command in emacs just executes bash -c "command" in my case. Solution is to start emacs (emacs &) in a shell where my .profile is already executed (instead of starting emacs from the GUI menus of my windows manager).
挖掘elisp源码;在我的情况下,emacs 中的 shell-command 似乎只是执行 bash -c "command" 。解决方案是在我的 .profile 已经执行的 shell 中启动 emacs (emacs &)(而不是从我的 Windows 管理器的 GUI 菜单启动 emacs)。

