upvote
It depends on what you are looking for. My recommendation for learning "how is X done in a shell" is the OpenBSD ksh: https://github.com/ibara/oksh

It's what they use for /bin/sh, it has everything that a complete shell needs (including a mechanism for providing command completions) and has code that is much easier to read than bash or zsh.

Something that I also would recommend is the design document for the plan9 rc shell; it is a worthwhile read for anybody interested in shells: https://doc.cat-v.org/plan_9/4th_edition/papers/rc

An implementation is also available if one wants to look at how it could be done: https://github.com/rakitzis/rc

reply
I don't know how real you want -- those criteria are probably self contradictory :-)

Marc Rochkind's book Avanced UNIX Programming implemented a basic shell, through iterations. You can see the first at e.g. here https://github.com/gmarler/AUPv2/blob/master/c5/sh0.c

It might be a bit old too. The book is very good but again, quite old. There seem to be free copies of it on the net.

BTW, does anyone know if Marc Rochkind is alive? His site basepath.com seems to be for sale :-(

reply
Although not the same... Destroy All Software has videos on building your own shell using Ruby. I watched it to learn and it was a lot of fun to watch him basically building a shell, I'm not really a Ruby guy, but it was easy to grasp. It's not free, you would need a subscription, but its worth the watch otherwise.

https://www.destroyallsoftware.com/screencasts/catalog/shell...

reply
I think there's a good one if you search around for "xv6 sh.c". Hard to tell immediately from a google search just now since there are many implementations (people do it in school) and github's currently blocking requests from my phone.

Also helpful may be running strace on your shell, then reviewing the output line by line to make sure you understand each. This is a VERY instructive exercise to do in general.

reply