简体   繁体   中英

Unix Subshell inheriting the command history from parent bash

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?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM