News for hackers. Stuff that matters.
Re:Create Your Own Shell in Python by acoderhasnoname on Wednesday July 06, 2016 @03:57PM (#12045451)
the pythonic way of doing this is: https://docs.python.org/3/library/cmd.html
Re:Create Your Own Shell in Python by Marazan on Wednesday July 06, 2016 @05:04PM (#12045903)
Reading the sorce code for cmd gave me my first "I am enlightened" moment when first programming in Python.

"You mean I just add a do_functionname method and that gives me a functionname command in the shell? And I can understand the 'refection' code that does this, and it dosen't look like incredibly verbose black-magiv-voodoo? I'm sold"

Re:Create Your Own Shell in Python by agumonkey on Wednesday July 06, 2016 @06:29PM (#12046310)
There are some youtube talks about python metaprogramming that you might enjoy later on. Your colleagues a little less.
Re:Create Your Own Shell in Python by rogerbinns on Wednesday July 06, 2016 @05:11PM (#12045937)
The python prompt toolkit is very nice too, providing a lot more modern functionality (eg syntax highlighting, mouse support, suggestions). http://python-prompt-toolkit.readthedocs.io/
Re:Create Your Own Shell in Python by pacaro on Wednesday July 06, 2016 @02:53PM (#12045070)
Another fun thing you can do is create a shell that only runs with the '-c' command line flag. If this is set as the default shell for a user, then you can use ssh as a simplistic rpc transport.
Re:Create Your Own Shell in Python by hackeradam17 on Wednesday July 06, 2016 @02:44PM (#12045032)
The funny thing is that I was literally just wondering about how shells are implemented right before getting on HN. Thanks for sharing, this should prove most useful :)
Re:Create Your Own Shell in Python by csl on Wednesday July 06, 2016 @04:51PM (#12045825)
If you often wonder about such things, I highly recommend the book "Advanced programming in the UNIX environment" by Stevens/Rago: https://en.m.wikipedia.org/wiki/Advanced_Programming_in_the_...

It covers a lot of stuff in an authoritative way. For example, how one should implement a daemon properly (e.g., chdir to root to allow for unmounting the disk the program originally ran from, lots of stuff like that). I'll actually doubly recommend it, because it's so good.

Re:Create Your Own Shell in Python by Nullabillity on Thursday July 07, 2016 @05:22AM (#12048308)
Of course, a lot of the daemon boilerplate no longer really applies in the modern systemd world.
Re:Create Your Own Shell in Python by JdeBP on Friday July 15, 2016 @02:56PM (#12103078)
It didn't in fact apply to a sizeable portion of the pre-systemd world, either. systemd doco gives the quite false impression that this stuff is new, for "new-style daemons". Not using this boilerplate has been the right way to write daemons for many systems over the past quarter century, going back to the release of the IBM System Resource Controller at the beginning of the 1990s.
Re:Create Your Own Shell in Python by rhinoceraptor on Wednesday July 06, 2016 @03:53PM (#12045416)
It's also shocking how simple pipes and redirection are. You just use the dup2 syscall to arrange file descriptors.
Re:Create Your Own Shell in Python by munyari on Wednesday July 06, 2016 @04:03PM (#12045482)
How does one implement logical connectives? (&&, ||)
Re:Create Your Own Shell in Python by OJFord on Wednesday July 06, 2016 @05:38PM (#12046058)
There are many ways that one might; perhaps the simplest might be to just define them as a builtin to your shell that checks the exit code of the left-hand command, and executes or doesn't the right-hand command accordingly.