Having to write my own shell in C for my operating systems class absolutely blew my mind. And then after that my professor made us implement a quine in the shell we just wrote. Yes, he was insane.
Which class/university was it? Any chance the materials are online?
I'm actually writing my own shell now; I'd be interested to compare :)
The fork/exec/pipe/dup calls are definitely an unusual and powerful paradigm. I think too many programmers don't know this because we were brainwashed to make "portable" programs, and that's the least portable part of Unix.
CS61 at Harvard covers that stuff, building your own shell (and memory management, etc) in C and it's an introductory class. There is a lot of hand holding of course but I really loved that class.
This looks pretty comprehensive for an undergrad project actually... they have a grammar and everything, with pipes and redirects, which are definitely the most Unix-y concepts. And they talk about interrupts, although no user-defined signal handlers or anything.
FWIW I ported the POSIX shell grammar to ANTLR, though I'm writing it in C++ (and prototyping the architecture in Python). ANTLR is actually incapable of expressing the lexer AFAICT...
Genuinely curious: what are some of the interesting things in writing your own shell? Was it the programming language interpretation aspect, or having to learn the kernel's API for forking tasks and redirecting, etc.?
Well it was my first low level experience so a lot of it was new to me - I hadn't even used C before so pointers alone were a revelation of sorts. I was blown away by the idea of interpretation and then once we delved into forking and processes (and zombie processes), well I truly went down the rabbit hole. It was really cool implementing your own system hooks with Minix - being able to press F12 to get a formatted tables of all running system calls was supremely satisfying. I fully appreciated how complicated and yet in a way beautiful OSes could be and it forced me to learn how to sweat the small stuff and build good software from the ground up.
Not OP but also had to write my own shell, as well as the kernel APIs for forking and whatnot. The kernel APIs are definitely interesting, but I think the biggest dopamine rush was once the way to parse and structure commands "clicked" and suddenly shells made a whole lot of sense.
also being able to look at the source code for a kernel and saying "ah ha! so that's where the process table is created" is also a lot of fun...kind of like uncovering ancient artifacts and learning to read the glyphs
this is going to sound crazy, but in eighth grade I took a CS class where they had us create an interpreter in lisp. It was amazing, and I haven't done anything quite like it since (though dan boneh's crypto class on coursera was close).
That sounds fun! Lisp is great for that because of its code-as-data principle (I use clojure in my day job and it makes dealing with structured data like JSON an absolute breeze). Did you go to an advanced school or something?
well, i started coding in 1st grade (logo, then basic) but this was a summer program hosted by Johns Hopkins. It was highly theoretical - we learned about DFAs, NFAs, epsilon-NFAs, and turing machines.
Awesome! I started in the 5th grade with Perl (lol) and went to a bunch of summer programs but they were more hands-on and programming based. Very cool. I learned about state machines when I was 16 and would draw my own really complicated ones for fun haha.
It's good to know about the existence of quines. But people are (presumably) paying good money for (and more important: investing their perfectly valuable time in) their education, and there's only so much time in a systems programming class, and so much more fundamental stuff to cover (or cover more robustly).
The people who really need to figure out how to write quines will no doubt find time to do so, in the dead of night, no matter what you may try to do to stop them. (And try to make them 3 bytes shorter than the shortest known version in that particular language). The rest -- they just need to know that they're out there.
Chill out, Franz. It was like a one day lab assignment and to be fair, I had no idea what quines were so I did learn something interesting and it led to an incredible discussion about Ken Thompson's "Trusting Trust".