Bash Examples

The Bash kernel runs code cells as Bash commands in a persistent Bash shell:


In [1]:
df -H


Filesystem      Size   Used  Avail Capacity  iused   ifree %iused  Mounted on
/dev/disk1      250G   229G    20G    92% 56050454 4941161   92%   /
devfs           188k   188k     0B   100%      636       0  100%   /dev
map -hosts        0B     0B     0B   100%        0       0  100%   /net
map auto_home     0B     0B     0B   100%        0       0  100%   /home

In [2]:
which python


/Users/bgranger/anaconda/envs/python34/bin/python

You can define variables that are persistent for the life of the kernel:


In [3]:
project="Jupyter"




In [4]:
echo "Hello to the $project project from $BASH"


Hello to the Jupyter project from /bin/bash

Tab completion works:


In [5]:
e


bash: e: command not found

You can define bash functions and use them in later cells. Here is a function that takes images over stdin and displays the in the notebook using the display architecture.


In [6]:
display ()
{
    TMPFILE=$(mktemp ${TMPDIR-/tmp}/bash_kernel.XXXXXXXXXX);
    cat > $TMPFILE;
    echo "bash_kernel: saved image data to: $TMPFILE" 1>&2
}



Here is an image from the Sloan Digital Sky Survey that is piped through the Jupyter display architecture:


In [7]:
cat images/sdss-galaxy.png | display