7

It's written in the Wikipedia page about od that:

Since it predates the Bourne shell, its existence causes an inconsistency in the do loop syntax. Other loops and logical blocks are opened by the name, and closed by the reversed name, e.g. if ... fi and case ... esac, but od's existence necessitates do ... done.

Is this the reason why do loops end with done?

2
  • 8
    The title mentions Bash, but the question seems to be about the (much older) Bourne shell. – Toby Speight Jun 23 at 16:34
  • It looks like you've just answered your own question – OmarL Jun 23 at 20:26
11

Yes, certainly. the method of bracketing control structures used in the Bourne Shell was ripped straight from Algol 68, in which loop “bodies” were enclosed between do and od.

This is a quote about it (from wikipedia):

Stephen Bourne's coding style was influenced by his experience with the ALGOL 68C compiler[2] that he had been working on at Cambridge University. In addition to the style in which the program was written, Bourne reused portions of ALGOL 68's if ~ then ~ elif ~ then ~ else ~ fi, case ~ in ~ esac and for/while ~ do ~ od" (using done instead of od) clauses in the common Unix Bourne shell syntax.

14
  • 2
    Bourne's pseudo-Algol C code used od: tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/mac.h – texdr.aft Jun 23 at 9:10
  • 4
    A more direct suggestion that the program od prevented the use of od as a keyword can be found (sans citation) in en.wikipedia.org/wiki/Od_(Unix). – chepner Jun 23 at 14:07
  • 2
    ENDSW instead of HCTIWS - what was SRB thinking??! – Toby Speight Jun 23 at 16:36
  • 4
    @DungSaga, ...it's a bit more indirect than that. bash isn't compatible with Bourne -- rather, it's compatible with POSIX sh. The POSIX sh standard definitely has a huge amount of Bourne influence, but compatible they're not -- for example, in true Bourne shell, ^ is a secondary pipe character, whereas it doesn't work that way in either POSIX sh or bash. There's an argument to be made that the POSIX sh standard was more closely drawn from ksh, which was modeled off Bourne... – Charles Duffy Jun 23 at 17:42
  • 2
    @DungSaga, ... remember, original Bourne is a product of the 1970s, whereas POSIX sh was standardized in 1992 (at which time ksh -- from which both bash and the POSIX sh spec drew inspiration -- had substantially improved the state of the art). That's a lot of years for nothing to change; of course a new shell released at the end of the 80s would be more similar to its contemporaries than to something a decade older. – Charles Duffy Jun 24 at 18:08

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.