iPython is a wonderful tool that avoids continuosly switching from bash to other utilities like bc, perl & co.
One of its limitation is the I/O redirection – at which bash is really good of. As iPython py-shell profile uses /bin/sh by default – thru os.system, I implemented a quick and dirty system replacement that diverts it into bash.
I added the following line here .ipython/profile_pysh/ipython_config.py
import os
def system2(cmd):
pid = os.fork()
if pid == 0:
args = ['/bin/bash', '-c', cmd ]
return os.execvp("/bin/bash", args)
else:
c_pid, status = os.waitpid(pid, 0)
return status
print("Overriding os.system with bash")
os.system = system2
# or you can simply use subprocess if available
os.system = lambda cmd: subprocess.call(cmd, shell=True,executable='/bin/bash')
While py-shell profile runs commands for every call outside python globals(), other profiles use the `bang` syntax.
Eg. ! ls -l
To work it out too, I just changed the following line in
/usr/lib/python2.7/dist-packages/IPython/utils/_process_common.py
71 p = subprocess.Popen(cmd, shell=True,
72 executable='/bin/bash',
73 stdin=subprocess.PIPE,