The Wikipedia page about od says:

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 really the reason why do loops end with done?

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

1 Answer 1


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.

  • 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, 2021 at 14:07
  • 3
    ENDSW instead of HCTIWS - what was SRB thinking??! Jun 23, 2021 at 16:36
  • 5
    @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... Jun 23, 2021 at 17:42
  • 3
    @DungSaga, try echo hello ^ cat. In POSIX sh or bash it outputs hello ^ cat; in real original Bourne it outputs just hello. (That test is how GNU autoconf distinguishes between original Bourne and POSIX-family shells like ash, dash, or bash). Jun 24, 2021 at 18:01
  • 3
    @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. Jun 24, 2021 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .