I want to source my bash environment when executing a bash command from IPython using the !
operator, thus allowing me access to my defined bash functions:
If the !
implementation uses IPython.utils._process_posix.system under the hood, then it is going to use whatever which sh
returns as the processing shell. This could be a true implementation of Bourne shell - it is likely Bash in some compatibility mode on many Linuxes. On my MacBook Pro it looks like it is a raw Bash shell:
In [12]: !declare -F
In [13]: !echo $BASH
/bin/sh
In [14]: !echo $BASH_VERSION
3.2.48(1)-release
In [15]: import os
In [16]: os.environ['SHELL']
Out[16]: '/bin/zsh'
I was hoping that it would use the $SHELL
environment variable but it does not seem to today. You can probably branch the github repo, modify the ProcessHandler.sh
property implementation to peek into os.environ['SHELL']
and use this if it is set instead of calling pexpect.which('sh')
. Then issue a pull request.