
A Bourne-style shell built from scratch in 35 minutes [video] - gary_bernhardt
https://www.destroyallsoftware.com/screencasts/catalog/shell-from-scratch
======
sillysaurus3
I'm surprised there are no comments about the video itself.

How was this video made? Imagine trying to make it. What would you do? You
need to write the code, but do you do it before or after you write the script?
Or do you write the script after you write up the code so you know how to
produce it?

Everything flows so smoothly. It's mesmerizing to watch. It's like code
appears as fast as he can talk. But in a natural way, where it seems like it's
typed as he's talking. But he certainly isn't typing it in realtime.

I'd like to make videos like this too, so I'd like to learn more about how to
produce one.

~~~
gary_bernhardt
That typing is in realtime! I rehearse screencasts until they flow naturally
like you see here; there's no content editing and no script. I basically
record the whole thing from beginning to end, over and over, until it doesn't
change significantly from run to run and I don't feel it catching anywhere.

I do edit out pauses to breathe, to drink water, sometimes to double-check my
thinking about what to do next, and occasionally to open a second terminal and
check something.

Destroy All Software is six years old, so I've had a lot of practice. Most DAS
screencasts require a couple hours of initial silent prep, then around 10 full
runs from beginning to end. When it starts to flow well (run #5, give or
take), I fire up ScreenFlow and start doing each run as if it might be the
final published version (because it might actually be). With these longer
"from scratch" screencasts, I only make one or two attempts per day; by then
my throat and brain are both pretty tired.

I also live stream these on Twitch before making the final version, so you can
see the sausage being made if you like! It's basically the same as what you
saw in this video, but the pauses are there, you get to hear me become
confused sometimes and comment on my mistakes, and there's a bit of Q&A
afterward. The schedule isn't fixed, but I try to tweet with a couple hours'
notice
([https://twitter.com/garybernhardt](https://twitter.com/garybernhardt)).

~~~
mbrameld
I learned a whole lot from your DAS screencasts! They came along at a time
when I was leaving my first software dev job where I had spent a decade doing
things the way they had always been done there. Things like automated testing,
MVC, and for the most part web development were all completely new to me. I
bet I watched most of them more times than you ran through them making them. I
would watch them over and over until I understood the concept, then find
places at work to apply what you taught me. Thanks for making them.

------
notheguyouthink
On this note, I need to build my own Terminal multiplexer - does anyone have a
favorite primer of theirs for all the escape codes? Not only do I need to use
them myself, but I need to handle them of child processes to restrict term
sizes etc.

I can Google like ya'll - I'm just asking if there are any favorite resources
:)

Thanks

~~~
tragomaskhalos
Not strictly answering your question, but years ago I worked on a job which
comprised a group of us sitting in a room, each with a VT100 connected to a
Unix box in the corner, cranking out C. We weren't _massively_ overworked, so
one clever bugger wrote his own terminal multiplexer on the side, enabling him
to flip between sessions using function keys. Another guy wrote a shell - _in_
Bourne shell. It had, errm, a few issues, but, crucially, gave us command line
editing and history (that was otherwise lacking in the vanilla sh we had, and
none of us fancied csh much).

~~~
noir_lord
My 2nd year college project (UK college not US very different things) was a
VT100 emulator written in Delphi.

In hindsight I should have done what the rest of the class did and took the
Blackjack option but there was the option to do our own project instead, I
demonstrated it worked by connecting it to my Linux laptop (this was '98, I
was a strange 18yo).

I was into LambdaMoo and mtrek at the time and I wanted to understand how they
worked better :).

------
kazinator
Then 35 weeks to get POSIX job control, pipes, handling signals and whatnot.
35 years to find the last bug.

~~~
egwynn
Not that I think writing a feature-complete shell is “easy”, but pipes,
specifically, were the main feature of this shell implementation (besides
reading, forking, and executing).

------
sigjuice
_It supports (1) running commands with arbitrarily many arguments_

Wouldn't the size of the arguments be limited by sysconf(_SC_ARG_MAX) as
explained here? [http://man7.org/linux/man-
pages/man2/execve.2.html](http://man7.org/linux/man-pages/man2/execve.2.html)

PS: Is the code available somewhere? I can't play the video on Firefox on
CentOS 6.

------
moomin
The Bourne Shell was, in my opinion, the worst of Robert Ludlum's books.

------
amelius
By the way, IMHO much of the ugliness of shells comes from the requirement
that simple filenames are to be used without additional escape characters. I
think we should ditch that requirement.

~~~
frou_dh
My fantasy crosscutting change is outlawing spaces in filenames, _at the
filesystem level!_

~~~
greggman
my fantasy is they design a shell language where it's impossible to write
anything that fails if there are spaces in filenames

~~~
hashhar
That's much better than what the parent wants. Almost always whenever I write
any script almost 25% of the time is spent ensuring it doesn't break due to
spaces or special unescaped characters.

~~~
frou_dh
You already have that. Just write your script in one of the countless sane
languages that are #!-able.

~~~
greggman
until your script needs to launch/spawn another app/script/command/program.

~~~
frou_dh
Doesn't necessarily have to be a major hassle. With my homemade Lisp, here's a
quick and dirty shorthand for running external programs (ultimately boiling
down to fork+exec):

    
    
        (extend-parser "!"
                       (mac (cmd) `(apply run (map to-string ',cmd))))
    
        !(sed "s/foo/bar/" README)

------
amelius
Only typing the man page of the Bourne shell will take at least a few days.

~~~
B1FF_PSUVM
Not to mention the time it takes to think it up, i.e. make the design
decisions.

"That's not writing, that's typing", as someone once put it.

------
teddyh
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
I’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
I read the description, but must have missed the part about pipes; oops.

------
pooonthis
Such negative Nellies. This is why I don't publish anymore. You try to teach
people something fun, and show people you can do quite a lot with very little.
But it's nothing but criticism, and none of it constructive.

~~~
gary_bernhardt
It depends on where you look. Hacker News is pathologically tilted toward
negative sentiment, usually in the form of look-how-smart-I-am. I also
announce these screencasts on Twitter, where the the response is universally
positive (in six years, I can't remember a single rudely negative comment
about a Destroy All Software screencast). Not that Twitter lacks its own
problems, of course!

------
reaperducer
Was expecting more guns, car chases, exotic city backgrounds, and slightly-
above-average women from the new Bourne shell. Turns out it's just a command
line interpreter. Two stars.

~~~
ibiza
Funny, but the shell's namesake is pretty badass himself
[https://en.wikipedia.org/wiki/Stephen_R._Bourne](https://en.wikipedia.org/wiki/Stephen_R._Bourne)

~~~
teddyh
“[…] _at one time Bell Labs had two Stephen R. Bournes with offices along the
same hallway._ ”¹

— Eric Allman

1\.
[http://www.sendmail.org/~ca/email/README.cf.8.8.html](http://www.sendmail.org/~ca/email/README.cf.8.8.html)

------
albedoa
Will this video eventually be paywall'd as well?

~~~
AlexeyBrin
The video has a download button (right click save as also works) if you want
to save it for later.

------
raoulj
I'm impressed that destroyallsoftware is able to put their screencast library
behind a $30/mo paywall. Am I the only one who thinks that's high?

~~~
tbodt
When you set up a paywall, you cut the number of people who will consume your
content by a ton, and then you have to set the price pretty high to make a
living.

~~~
AlexeyBrin
The reverse being that with a ton of people that watch your free content you
will probably make less than what the author currently makes.

------
Scarbutt
But 'ls' already has built-in sorting.

------
Fiahil
I was so disappointed that they chose Ruby. I would have been impressed if
they had chosen bare C and still manage to build it under 35 minutes.

~~~
torstenvl
For my system programming class we had to write a Unix shell in C. I
procrastinated and wrote the whole thing in one 38-hour caffeine-fueled sprint
on a 32-bit SPARC SunStation. I don't think it supported pipes but it did
support input/output redirection and ANDing of commands. Not my best product,
but some of my best work.

------
randrews
This was one of the projects in my Unix class in college. And yeah, it took
about 35 minutes. :)

