3 ms·
There is more to writing a shell than simply reading commands and executing them after fork()ing. TTY handling must be done right¹ and interrupt and signal hand
by teddyh 9y ago
There is more to writing a shell than simply reading commands and executing them after fork()ing. TTY handling must be done right¹ and interrupt and signal handling is rather tricky to get right as well².
(Not to mention, of course, that a Unix shell is very cumbersome to use without pipes and redirection. EDIT: Pipes are implemented, but not redirection?)
1. http://www.linusakesson.net/programming/tty/ http://www.linusakesson.net/programming/tty/
2. https://www.cons.org/cracauer/sigint.html https://www.cons.org/cracauer/sigint.html
- egwynn 9y agoI’m not sure if you watched the video or read its description, but pipes are the focus of this implementation. He describes pipes as “the core of the UNIX shell” in the video. I suppose that is somewhat up for debate, but building complex tasks out of composable pieces is certainly up there among UNIX’s design goals, and pipes are a big part of that. OTOH, his implementation does not seem to cover output redirection à la `exec` (file-based, file-descriptor-based, or named-pipe).
- teddyh 9y agoI read the description, but must have missed the part about pipes; oops.
- hawkice 9y agoIf the implementation done in less than an hour is not featureful enough for you, obviously you don't have to use it. Doesn't reflect the value in this type of post on HN. If it was insufficiently pedagogical, or failed to give people the impression that shells are just software and They Can Do It Too, then I would understand the critique more, as those are clearly the goals.
- teddyh 9y agoI was trying to notify readers that the description is rather inaccurate; The HN title claims “Bourne-style shell”, and the article claims “shell in the style of the Bourne shell, Bash, zsh, etc.”, but a working shell actually requires TTY and signal handling; they’re not really optional features. Sure, if all you’re doing is implementing a program with a command line interface like ftp(1), kermit(1), sftp(1), etc. that do not run arbitrary subprocesses, and do not need to handle being arbitrarily interrupted, then sure, implement away. I would suggest the Python “cmd” library as a good way to get started quickly. But for a login shell, used to run other programs, there are more complex considerations.