Unix Subshell inheriting the command history from parent bash

一个人想着一个人 提交于 2019-12-23 04:57:26

问题


I have written a series of python tools that spawn new bash sessions. I am want those individual subshells to inherit the command history of the parent. I have tried:

shopt -s histappend
PROMPT_COMMAND="history -an;$PROMPT_COMMAND"

in the .bash_profile. But it didn't give me what I need. I have seen this done. My tool uses:

os.system('bash')

to spawn a subprocess.

Thoughts? better way?


回答1:


site.py sets os.environ at startup. This does not change unless you explicitly change os.environ. So, a call to os.system('/bin/bash') should have an environment that was the same as you got as python startup.

Check os.environ, right after startup, and if necessary make changes to os.environ. Directly.

python docs os




回答2:


Depending on your OS, .bash_profile may only be executed by login shells, while .bashrc is executed for non-login shells.

So try putting

shopt -s histappend
PROMPT_COMMAND="history -a; history -n"

in .bashrc instead of .bash_profile.



来源:https://stackoverflow.com/questions/17030034/unix-subshell-inheriting-the-command-history-from-parent-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!