Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In bash at least, if and case blocks are closed like this:

if some-expr
    echo "hello world"

case $some-var in

as opposed to the more typical close of end or endif/endcase. As far as I know, this rather funny convention is unique to shell scripting and I have never seen such an odd block terminator anywhere else. Sometimes things like this have an origin in another language (like Ruby's elsif coming from Perl), or a strange justification. Does this feature of shell scripting have a story behind it? Is it found in other languages?

share|improve this question
It appeared in Algol68 somewhere in the 1960s. I'm not sure who's idea it was. If you dig through you might be able to spot who. A few other languages do use it, eg has it hidden as an alternative. – NevilleDNZ Nov 23 '12 at 6:46
up vote 11 down vote accepted

According to Wikipedia, the sh program reused the syntax from ALGOL 68.

Stephen Bourne carried into this shell some aspects of the ALGOL 68C compiler that he had been working on at Cambridge University. Notably he reused portions of ALGOL 68's "if ~ then ~ elif ~ else ~ fi", "case ~ in ~ esac" and "for ~ while ~ do ~ od" (using done instead of od) clauses in the common Unix Bourne shell syntax.

Since Bash was the GNU replacement of sh, it reused the same syntax for backwards compatibility.

share|improve this answer
I guess Bourne used done rather than od because od is a command (octal dump). – Keith Thompson Jun 12 '12 at 5:39

No. You find these "reversed" language constructs in many languages:

  • { and },
  • /* and */
  • (* and *)


share|improve this answer
Not to mention the "ohm" and the "mho"... :-) – NevilleDNZ Nov 23 '12 at 6:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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