Bring the good part of Shell scripting to Python.
$ pip install shell.py
>>> from shell import ex
>>> ex('echo hello shell.py').stdout()
'hello shell.py\n'
from shell import p
pipeline = (p('ifconfig')
.p('grep -A 1 eth0')
.p('grep inet')
.p('awk "{print $2}"')
.p('cut -d: -f 2'))
print pipeline.stdout()
Or
from shell import pipe_all
pipeline = shell.pipe_all(['ifconfig',
'grep -A 1 eth0',
'grep inet',
'awk "{print $2}"',
'cut -d: -f 2'])
print pipeline.stdout()
>>> from shell import instream
>>> instream('1 2 3').p('awk "{print $1}"').stdout()
'1\n'
This is equivalent to:
>>> from shell import ex
>>> ex('echo 1 2 3').p('awk "{print $1}"').stdout()
See test cases for more examples.
Run tests with nosetests(at least v1.3.0):
make test