The line editor ed in UNIX/Linux has a "command mode" and an "insert mode" and there is no visual way to tell which mode you are in. However, there is a -p option that causes it to display a prompt when you are in command mode, which is very helpful.

Why is the default to have no prompt? Masochism?

  • 11
    All of classic Unix is extremely terse. Notice also that most commands like cp or rm return no message upon completion, unless there's an error. The first terminals were usually printing teletypes running at an excruciating 110 baud. Every character printed meant time, paper, ink and mechanical wear. So extreme frugality was the practice. – RETRAC Dec 7 '19 at 17:51
  • Please write answers in the answer section – Lightness Races in Orbit Dec 8 '19 at 19:50
  • 2
    @LightnessRaceswithMonica I commented because sadly, it's not really an answer. Just some background context. I don't know why ed doesn't even have a prompt, given that e.g. the shell does. Just wanted to point out that terseness is a tendency in Unix systems. – RETRAC Dec 9 '19 at 17:46

Having used ed years ago on a printing terminal (such as a teletype or a DECwriter), I think the reason for having no prompt was that on pressing RETURN after one command, you didn't have to wait for a prompt to be printed before starting to type the next command.

Similar considerations made it better for ed to have ? as the only error message: you would have worked out what the mistake was long before a longer error message had finished printing.

  • 5
    Actually, ed had a second error message: it printed ?tmp if its temporary file was full. – Mike Spivey Dec 6 '19 at 12:36
  • Right... and those error messages go to stderr. – O. Jones Dec 7 '19 at 21:10
  • @O.Jones: Not in the Sixth Edition. – Mike Spivey Dec 7 '19 at 22:40
  • On a system which echos characters when they are read, the delay wouldn't be an issue, but you raise a good point about systems which echo them as they are typed--an approach which may be good from a CPU usage perspective, but is bad as a UI. – supercat Dec 18 '19 at 23:24
  • I think you misunderestimate the psychological effect of trying to type on machines that noisy while holding the changes you'd planned in your head! – Mike Spivey Dec 19 '19 at 20:01

When I was a lad, the only reason ed was included at all in our environment is because it was used by the standard system scripts.

Originally, having to clean the 'prompts' out of ed output to clean up the data would have just made everything more difficult -- much more difficult.

Later, having ed default to something different would have just broken all the existing scripts.

  • 2
    Welcome to RC.SE, necromancer2! :-) – cjs Dec 6 '19 at 4:06
  • Sounds like your beard have hardly greyed yet... – Thorbjørn Ravn Andersen Dec 21 '19 at 15:57
  • Fair point. Some of us learned ed in '01 just so we could write scripts that edit text files. I decided I'd rather script vi. Man that gave the grader a headache. – Joshua Jun 15 '20 at 16:25

However, there is a -p option that causes it to display a prompt when you are in command mode

The -p option is meant to set a different prompt. When used, a side-effect is that ed starts in addition with prompt enabled.

Why is the default to have no prompt?

There is a default, * (asterisk); it's just not switched on. Prompt display can be toggled by applying a P command (*1).

Ed is meant as well for automated (scripted) use (*2). Having the prompt displayed for each command entered is at least annoying; on a real TTY it will waste a lot of paper.

To display no prompt by default seems sensible in an early environment, doesn't it?

In addition, it might be good to keep in mind that programming back then, especially when done online, was handled mostly in the head, not on a screen or alike. When using ed, one had to have a proper image present. Printing the whole file or just parts thereof would eat up a lot of paper and even more important time. Listing just a page would easily take a minute or two.

With that background it's rather trivial to keep aware what mode one is in. After all, it's not complicated, as default is command and input is only activated on request.

*1 - The prompt is a rather new addition as Stephen Kitt mentioned.

*2 - I always loved the feature to 'open' any shell command as input 'file'.

In fact, ed even predates next to all other Unix tools as well as basic output direction itself (which was a shell feature until pipes were added in V3 (?)). So the standard way to capture a program output was to 'open' it as ed input file and save it as text file:

$ ed
r !ls -l
w directory_listing
  • 5
    “To display no prompt by default seams sensible in an early environment” — indeed, although it might not be obvious why nowadays ;-). Incidentally, older versions of ed don’t support prompts at all, they’re a somewhat recent addition. – Stephen Kitt Dec 5 '19 at 20:15
  • @StephenKitt was it? I never thought about - in fact, I never used P at all, just looked it up a few minutes ago. Do you know when it was added? – Raffzahn Dec 5 '19 at 20:28
  • 4
    I’m not sure when it was added; even the V10 manpage doesn’t mention it, I think it came from BSD — 3BSD has it. So “somewhat recent” for some values of recent, around 40 years ago ;-). – Stephen Kitt Dec 5 '19 at 22:30
  • 4
    Browsing through minnie.tuhs.org, in V6 (1975), 'P' is an error. In V7 (1979) 'P' was a synonym for 'p'. In Sys III (1982), 'P' toggled the prompt. – Kelvin Sherlock Dec 5 '19 at 22:48
  • 1
    @KelvinSherlock Thanks. :) I guess we all have forgotten how incompatible various Unix versions and derivatives were over time. – Raffzahn Dec 6 '19 at 1:48

The -p option is a late addition. I did some checking and the Seventh Edition man page for ed doesn't mention the -p option, but it does appear in the Ultrix 4.2 man page. Fifth Edition Unix also doesn't mention a -p option, but it does say that if ed is invoked as a login shell (i.e. the program name provided in argv[0] is "-") that it will enable a * prompt. This was presumably done in support of the early use of Unix as a text editing system.

I am guessing that the -p option was added to provide an easier way to enable a prompt without jumping through the required hoops to invoke ed with arg[0] set to "-". But by that time, I suspect that very few people were still using ed for interactive editing: vi/ex and Emacs would have taken over for most. If you were still using ed, you were either familiar with it already due to using it for many years (in which case you wouldn't need the prompt), or you were using it non-interactively (giving it input from a file) and you wouldn't have wanted prompts anyway.

  • The P command was first found in UNIX System III. I think the -p option was first added in UNIX System V. – Greg A. Woods Mar 21 '20 at 19:23

Looking at the previous answers I see everyone has missed an essential feature most system run level 1 commands, and that is that they were amenable to piping. The non-interactive mode is therefore the default in ed, ex, sed, awk, grep etc

TFTP (Trivial FTP) is also another good example of a stripped down version of FTP used in disk-less boot-up processes to boot from a remote network boot image. No user prompts are emitted as is done in the full-blown FTP.

  • 2
    I see why you wouldn't prompt when stdin was not a tty, but that in itself doesn't explain the lack of a prompt when stdin is a tty. – another-dave Dec 8 '19 at 21:00
  • It is not easy to apprehend the situation of prior eras. An earlier answer mentioned that the editing was done in one's head, not on the teletype. That applied to many other subtleties. Ed column numbers matched the imagined document, and column 1 was where imperative text went just as in the intended memory copy. So whence the prompt? – MKhomo Dec 8 '19 at 21:50
  • It's easy enough to apprehend a prior era when one remembers actually driving a teletype in said era. :-) Apropos 'column numbers', sure, the first character entered on a line was logically "column 1", but since teletypes don't actually have numbered columns, there's no problem if "column 1" is printed after a "*". In any case, I understood the question to be about a prompt in command mode, not in text-input mode, so column numbers aren't really a consideration. – another-dave Dec 8 '19 at 21:56
  • I lost some edits after the prompt? question in my prior comment. But perhaps I could reverse the apprehension issue by asking what purpose one would suggest the prompt would / should serve within the scope of 'ed' functionality which does recognize line and column numbers? As far as I remember it was to perform edit actions on the 'ed' buffer, although the bang (!) allowed escape to shell. Don't recall if 'ed' supported multi-buffer yank / put etc – MKhomo Dec 8 '19 at 22:20
  • I see no useful role for the prompt when in insert mode. I think a prompt is useful in interactive command mode since it conveys "done that thing, ready for the next thing". But then, I'm just describing all of the various non-display-oriented editors used. – another-dave Dec 8 '19 at 23:39

Because of the universality of printing terminals when ed was current. An editor prompt on each data line would have consumed space on the paper, which would have cut that much off of what you could type into each line, and see. Printing terminals didn't autowrap, and typing blindly off the end of the line was Unpleasant. Even if they had autowrap, that would have consumed more paper, and reduced the correspondence (on paper) between what you had typed the first time, versus what you'd see if you then printed it again (sans prompts). (Conservation of paper was a significant issue, even if it was just to prevent you from becoming mired in an overlarge pile of paper from your session.)

  • I'm not talking about data lines. I'm talking about command mode. The point is to be clear about what mode you're in. By default it doesn't give you a prompt even in command mode. It's very confusing to not be sure whether you're in command or data entry mode. – JoelFan Mar 18 '20 at 16:48
  • 3
    If you weren't sure you would just scan up the paper to see what you had done recently, it really wasn't too hard to tell what mode you must be in at the moment. Also, most text interpreted as commands would piss ed off in some way, and the "?" was a pretty good clue that you'd guessed wrong. – jimc Mar 18 '20 at 16:52
  • 3
    Life on a 10-cps printing terminal really was different in a lot of ways, it's hard to envision this if you've never had to live it. – jimc Mar 18 '20 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.