Have you ever used the UNIX program grep?

A recent discussion in Remark.as triggered by a Paolo Amoroso's post remind me of the following story, nicely put together by Brantley Coile.

Ken Thompson is one of the greatest living legends in the story of Computing Science for his work on UNIX and the C programming language. Interestingly, he's still quite active. He now works for Google on the design of the Go programming language (a.k.a Golang). Artists can't stop working, they never go into retirement, simply because they make no distinction between work and life.

A few more curious facts. Golang is the programming language Matt Baer used to implement WriteFreely, the software where write.as (and hence, this blog) runs. The design of not only the Linux kernel, but also the kernel of your MacOS is based on the UNIX design. Most of the servers in the world run operating systems using the Linux kernel, and a large portion of those which don't, use a kernel which design is based on ... you guessed it, UNIX. Thus, when you say your application runs on the cloud, you are actually referring to a bunch of remote servers running some UNIX-based OS.

People like Ken will never receive the amount of public recognition he deserves outside the small computer geek circles. It is not like he cares about it, but I hope this short post helps to fix that, even though that's pretty much like trying to fill the ocean with a drop of water.

Now the story.

Have you ever used the UNIX program grep?

Ever wonder where it come from or why it has such a strange name?

In the beginning, UNIX ran on a PDP-7 and was written all in assembly language. There were only a handful of tools: ls, mv, rm, mkdir, chdir(sic), as (the assembler) and ed the text editor.

Even though things were very simple, the text editor ed had a full implementation of regular expression pattern matching. Ken Thompson based it off his work at Berkeley years before on a text editor called QED.

In this early UNIX environment, to search for a pattern in a file, you opened the file in ed and then did a “g/search-string/p” command, where “search-string” was a regular expression.

One day Ken got tired of having to get into ed for every stinking file he needed to search and decided to do something about it. He copied ed.s (remember, all assembler) to s.s and started cutting. If a line of s.s didn't do regular expressions, it was out. The result was that his command “s” did searches with regular expression on one or more files.

Not wanting to be “that guy” who pushes all his bad ideas out to the world (I'm not sure I know of anyone who thought he ever had a bad idea) he kept the new command in his private bin directory /usr/ken/bin.

One day Dough McIlroy, who many think was the smartest of the early UNIX folks and least recognized, asked if Ken “...could write something that did regular expression searches without having to get into the editor.”

“Let me think about it,” Ken answered.

That night, Ken issued the command “mv /usr/ken/bin/s /usr/bin/grep.”

The next morning, Ken showed the new command to Doug and asked, “Is this the kind of thing you were thinking of?”

“Perfect!” Doug replied, impressed with how fast Ken could cook something like this up.

Why “grep?” Ken couldn't use the command “s” for a public utility. It's too short. We use one letter commands all over the place but only locally. I have “m” and “r” script files everywhere, the former runs “make” and the latter is a test script.

So g/RE/p leads one naturally to grep. It was just on the spur of the moment decision. That's the story of how we got grep and how it got its name.

Oh, and Ken told Doug about why the development cycle was so fast.

Joe Condon and Ken Thompson revisiting the 1978 ACM BLITZ 6.5-Belle game (1982). Joe Condon and Ken Thompson revisiting the 1978 ACM BLITZ 6.5-Belle game (1982). [Source]

#Computer #Science #Software #UNIX #Stories