TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Writing a Unix Shell – Part II

210 点作者 dhanush将近 8 年前

3 条评论

kevindong将近 8 年前
If you want to learn more about writing a shell from an undergraduate coursework perspective (and far closer to how bash does things), this is a chapter entirely on writing your own shell: <a href="https:&#x2F;&#x2F;www.cs.purdue.edu&#x2F;homes&#x2F;grr&#x2F;SystemsProgrammingBook&#x2F;Book&#x2F;Chapter5-WritingYourOwnShell.pdf" rel="nofollow">https:&#x2F;&#x2F;www.cs.purdue.edu&#x2F;homes&#x2F;grr&#x2F;SystemsProgrammingBook&#x2F;B...</a><p>That PDF covers the basics of making your own shell (i.e. splitting input into tokens aka using a lexer, parsing the resulting tokens aka using yacc [a token parser], I&#x2F;O redirection, piping, executing commands, wildcarding, interrupts, environmental variables, history, subshell, revising what you&#x27;ve typed without having to retype it, etc.).<p>Every undergraduate CS major at Purdue University is required to do the infamous shell lab (essentially, recreate csh). This project really taught me how shells work. Before doing this project, I could do the minimum in shells, but now I&#x27;m fairly competent at it.
评论 #14550233 未加载
评论 #14550301 未加载
评论 #14551092 未加载
pacaro将近 8 年前
Thanks for continuing your series.<p>This is a great illustration of how non-trivial a production quality shell is.<p>Parsing input is &quot;tricky&quot;<p>Each builtin needs comprehensive error handling
评论 #14550062 未加载
tyingq将近 8 年前
Still missing the check for fork returning -1, which would make your waitpid() hang forever, as -1 waits on all p̶i̶d̶s̶,̶ ̶e̶v̶e̶n̶ ̶i̶n̶i̶t̶.̶ children.<p>Edit: less problematic than my original wrong guess, but still bad for a shell, which eventually supports multiple concurrent children.
评论 #14549986 未加载