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   197G    53G    79% 48081657 12909958   79%   /
devfs           186k   186k     0B   100%      628        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/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




In [ ]: