Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Write a Shell in C (stephen-brennan.com)
93 points by xvirk on Jan 18, 2015 | hide | past | favorite | 8 comments


What if the shell itself receives a signal while running another process? You need to handle this very carefully:

http://www.cons.org/cracauer/sigint.html

Yes, this is easy to do simplistically and wrong, but very important to get right, even for regular programs, let alone a shell.


I really like this article. It shows that we don't need inferiority syndrom and instead can create the next Bash or zsh, etc. I personally think that small unix tools and shells will never cease to feel a bit like magic


I just did an exercise like this as I'm following the Caffeinated 6.828 operating systems course from MIT for fun: https://sipb.mit.edu/iap/6.828/lab/shell/

That assignment was adding some features (command execution, pipes, redirection) onto an read-parse-loop "shell" program.


This was my first assignment for my Systems Programming course in my undergrad - really enjoyed that assignment as the lecturer gave 20% the total assignment mark for you to implement whatever you'd like


I had this assignment too. It seems that writing a shell in a low level language is great for learning multiple important topics in one project: memory management, input/output to terminal, string parsing and process management. Once you understand these things, you are well on the way of becoming a competent programmer.


If this interests somebody, then I suggest they'd read "The Unix Programming Environment" By B.W Kernighan, and Rob. Pike. It gives you the concepts, and learns you tools like yacc, that lets you off a lot of tedious tasks when writing an interpreter of sorts. Then follow up with at least "Advanced Unix Programming" By Stevens.

The universe of commandline tools is still not completed, and this kind of programming is fun! fun! fun!

Personally I miss the Plan-9's plumb utility. :)


I too had this assignment. It is ironic, I put way to much effort and time into this project, and had something I was rather proud of. A large section of the class used hand me down code from previous classes and had a somewhat more polished product. It ended up that I go my only C+ in four years, but I would say I learned more than in most of my classes.


i really enjoy articles that demystify the tools and programs that we all take for granted. i don't think i'm going to be writing my own shell any time soon though..!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: