Paul Joseph Davis

Unix in 13 lines of Python - Mostly trivial
===========================================

I found this [1] fairly amusing, but just a big if statement? So I
ported it to Python. I was reminded that iterating over stdin in Python is
always a bit weird. I generally create an iterator that just yields
sys.stdin.readline() forever, but went more hackish here to conserve lines and
add lulz.

    import sys
    print "You have no mail"

    commands = {
        "uname": lambda args: "Punix 1.0",
        "halt": lambda args: exit(0)
    }
    error = lambda args: "Command not found."

    sys.stdout.write("$ ")
    for line in (sys.stdin.readline() for i in xrange(sys.maxint)):
        print commands.get(line.split()[0], error)(line.split()[1:])
        sys.stdout.write("$ ")

References
----------

[1]:  http://pwpwp.blogspot.com/2009/11/unix-in-14-lines-of-ruby-its-trivial.html


Copyright Notice
----------------

Copyright 2008-2010 Paul Joseph Davis

License
-------

http://creativecommons.org/licenses/by/3.0/