Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute Bash command from IPython

Tags:

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:

In[2]: !<my_fancy_bash_function> <function_argument> 

currently IPython is sourcing sh rather than bash:

In[3]: !declare -F sh: 1: declare: not found 

How to source bash and set my environment settings from IPython?

like image 266
chris Avatar asked Apr 10 '13 13:04

chris


People also ask

Can I run Linux commands on Jupyter notebook?

Linux commands and exercises are designed to be executed from a Linux terminal. However, there are several different ways that most of this functionality can be achieved from the Jupyter notebooks with the attendent advantage of built-in documentation capabilities.


1 Answers

Fernando Perez, creator of IPython, suggests this:

In [1]: %%bash . ~/.bashrc <my_fancy_bash_function> <function_argument> 

This works on the current stable version (0.13.2). He admits that's a bit clunky, and welcomes pull requests. . .

like image 51
Jason Sundram Avatar answered Nov 09 '22 01:11

Jason Sundram