Skip to content

qiao/shell.py

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shell.py

image

image

Bring the good part of Shell scripting to Python.

Install

$ pip install shell.py

Usage

Execute a shell command

>>> from shell import ex
>>> ex('echo hello shell.py').stdout()
'hello shell.py\n'

Pipe commands

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()

Use string as command input

>>> 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.

Tests

Run tests with nosetests(at least v1.3.0):

make test

About

shell power for python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%