Field notes and occasional musings by Peter on Stuff that happens, from a free software perspective, mainly OpenBSD, FreeBSD.
Sunday, April 1, 2018
ed(1) mastery is a must for a real Unix person
In some circles on the Internet, your choice of text editor is a serious matter.
We've all seen the threads on mailing lits, USENET news groups and web forums about the relative merits of Emacs vs vi, including endless iterations of flame wars, and sometimes even involving lesser known or non-portable editing environments.
And then of course, from the Linux newbies we have seen an endless stream of tweeted graphical 'memes' about the editor vim (aka 'vi Improved') versus the various apparently friendlier-to-some options such as GNU nano. Apparently even the 'improved' version of the classical and ubiquitous vi(1) editor is a challenge even to exit for a significant subset of the younger generation.
Yes, your choice of text editor or editing environment is a serious matter. Mainly because text processing is so fundamental to our interactions with computers.
But for those of us who keep our systems on a real Unix (such as OpenBSD or FreeBSD), there is no real contest. The OpenBSD base system contains several text editors including vi(1) and the almost-emacs mg(1), but ed(1) remains the standard editor.
Now Michael Lucas has written a book to guide the as yet uninitiated to the fundamentals of the original Unix text editor. It is worth keeping in mind that much of Unix and its original standard text editor written back when the standard output and default user interface was more likely than not a printing terminal.
To some of us, reading and following the narrative of Ed Mastery is a trip down memory lane. To others, following along the text will illustrate the horror of the world of pre-graphic computer interfaces. For others again, the fact that ed(1) doesn't use your terminal settings much at all offers hope of fixing things when something or somebody screwed up your system so you don't have a working terminal for that visual editor.
ed(1) is a line editor. And while you may have heard mutters that 'vi is just a line editor in drag', vi(1) does offer a distinctly visual interface that only became possible with the advent of the video terminal, affectionately known as the glass teletype. ed(1) offers no such luxury, but as the book demonstrates, even ed(1) is able to display any part of a file's content for when you are unsure what your file looks like.
The book Ed Mastery starts by walking the reader through a series of editing sessions using the classical ed(1) line editing interface. To some readers the thought of editing text while not actually seeing at least a few lines at the time onscreen probably sounds scary. This book shows how it is done and while the author never explicitly mentions it, the text aptly demonstrates how the ed(1) command set is in fact the precursor of of how things are done in many Unix text processing programs.
As one might expect, the walkthrough of ed(1) text editing functionality is followed up by a sequence on searching and replacing which ultimately leads to a very readable introduction to regular expressions, which of course are part of the ed(1) package too. If you know your ed(1) command set, you are quite far along in the direction of mastering the stream editor sed(1), as well as a number of other systems where regular expressions play a crucial role.
After the basic editing functionality and some minor text processing magic has been dealt with, the book then proceeds to demonstrate ed(1) as a valuable tool in your Unix scripting environment. And once again, if you can do something with ed, you can probably transfer that knowledge pretty much intact to use with other Unix tools.
The eighty-some text pages of Ed Mastery are a source of solid information on the ed(1) tool itself with a good helping of historical context that will make it clearer to newcomers why certain design choices were made back when the Unix world was new. A number of these choices influence how we interact with the modern descendants of the Unix systems we had back then.
Your choice of text editor is a serious matter. With this book, you get a better foundation for choosing the proper tool for your text editing and text processing needs. I'm not saying that you have to switch to the standard editor, but after reading Ed Mastery , your choice of text editing and processing tools will be a much better informed one.
Ed Mastery is available now directly from Michael W. Lucas' books site at https://www.michaelwlucas.com/tools/ed, and will most likely appear in other booksellers' catalogs as soon as their systems are able to digest the new data.
Do read the book, try out the standard editor and have fun!
6 comments:
Note: Comments are moderated. On-topic messages will be liberated from the holding queue at semi-random (hopefully short) intervals.
I invite comment on all aspects of the material I publish and I read all submitted comments. I occasionally respond in comments, but please do not assume that your comment will compel me to produce a public or immediate response.
Please note that comments consisting of only a single word or only a URL with no indication why that link is useful in the context will be immediately recycled so those poor electrons get another shot at a meaningful existence.
If your suggestions are useful enough to make me write on a specific topic, I will do my best to give credit where credit is due.
This is by far the very best book review I've ever read, and it does "ed mastery" justice.
ReplyDeleteI don't know, When switched to ed from teco I found it sort of limiting.
ReplyDeleteOf course when I tried to use teco again after many years, My memory of it seemed to have surpassed reality, but that's often the case after 30 years.
Great post and really interesting information but I fail to see why one would still be using Ed. I have been using Linux for some time now and I had little to no contact with real Unix. Would you care to illuminate me?
ReplyDeleteed leads to sed. sed leads to vi. vi leads to vim. vim leads to gvim. gvim leads to mousing around vi. mousing vi leads to SUFFERING!
ReplyDeleteI've had times where a terminal and the connected system simply would not cooperate, and ed was about the only viable editor. Since vi was one of the first things I learned on unix, it was fairly painless. And as you mention, sed is also easily understood if you already know ed or vi, and I already got along quite well with sed, awk, and grep by the time Larry's scripting language was gaining traction. Seeing how tools like these related to each other also kind of helped illustrate the beauty of unix as a cohesive system, and thus lent understanding of why doing things certain ways was preferable.
I only just now saw this. ed has saved my butt many times! Being able to use ed should almost be a requirement for using Unix-like anything. Wonderful and fairly simple. +1
ReplyDeleteI bought myself this book as a birthday gift and am very pleased. It's light-hearted, entertaining and instructive. I tend to go to the root of things so I quickly discovered the Unixverse and ed (1) and when I saw this book I wanted it bad. Of course I could, as @mwlucas suggested, study the source code and manpage, but I don't speak C and man is NOT a tutorial (and not as funny as Lucas).
ReplyDelete__Unknown__ commenting on May the 20th don't seem to have read your review properly as he's not getting the **why** of learning ed(1): It's the standard editor! If all else fail, ed (1) should still work. Many other tools and techniques evolved from/via it (regex'es and vi(1) still has a variant called ``ex`` as a built in line editor (when you type commands on the bottom of the page)). It will not distract you, it will keep your scripts less bloated, etc.
I highly recommend following ed(1)conference for frequent tips and memes. Here:
https://bsd.network/@ed1conf
or on Twitter (if you prefer locked down, centralized, proprietary platforms).
Also: a quick search on GitHub revealed several interesting evolutions of ed(1): a file manager with ed(1) syntax, like ranger(1) to vi(1). But the coolest
: A web browser, js included, with an ed(1) interface! Made by a blind man. It is awesome for automation of simulated web site interactions: edbrowse(1).
It has been, since I got the book, my standard editor, but still lots more to learn :)