Shell Is this a switch?

I have been studying software some and I wonder if this would be considered a programmatic switch?

/usr/local/share/poudriere/bulk.sh

Code:
SNIP
while getopts "ab:B:CcFf:HiIj:J:knNO:p:RrSTtvwz:" FLAG; do
        case "${FLAG}" in
                a)
                        ALL=1
                        ;;
                B)
                        BUILDNAME="${OPTARG}"
                        ;;
                b)
                        PACKAGE_FETCH_BRANCH="${OPTARG}"
                        validate_package_branch "${PACKAGE_FETCH_BRANCH}"
                        ;;
                c)
                        CLEAN=1
                        ;;
                C)
                        CLEAN_LISTED=1
                        ;;
 

Very similar to this but without the 'switch' statement?
 
What is known as "switch" in some programming languages is known as "case" in some others, and sometimes even "match". Some languages completely forego it, and instead use chains of if - elif - elif. I think the oldest version is the Fortran computed goto (closely related to the 3-way if in original Fortran).
 
Very similar to this but without the 'switch' statement?
Yes. Steve Bourne, who wrote Unix V7 /bin/sh, was influenced by Algol68 and borrowed constructs such as case ... esac, if ... fi from it. Though curiously a68's for .. do .. od became for .. do .. done! He even used some a68ish C macros so that his /bin/sh C code looked a bit like a68 code!
[Edit: a68 is a beautiful, consistent language in spite of being designed by a committee. Better than many that followed it.]
 
I think the oldest version is the Fortran computed goto (closely related to the 3-way if in original Fortran).
gcc added this to their version of C. Ages ago I wrote a 6811 simulator using C macros for its main switch that allowed you to use a C's standard switch stmt or gcc's computed goto. The latter version ran twice as fast (both ran faster than the real 68hc11 I had back then!)
 
I think the oldest version [of a switch] is the Fortran computed goto (closely related to the 3-way if in original Fortran).
I believe that FORTRAN's "assigned GOTO" would also qualify:
Code:
ASSIGN 1000 to LEG
...
ASSIGN 2000 to LEG
...
GO TO LEG
I used computed GOTOs frequently, as they were a succinct multi-way switch mechanism, but never assigned GOTOs. They were too difficult to debug!
 
For a historical perspective, you may find interesting:
  1. Early days of Unix and design of sh by Stephen R. Bourne - NYC Bug 2015
  2. Stephen Bourne: Early days of Unix and design of sh - BSDCan 2015
    slides (from BSDCan 2015 - Keynote)
#2 has much better audio, but Steven Bourne not shown while presenting.

Yes. Steve Bourne, who wrote Unix V7 /bin/sh, was influenced by Algol68 and borrowed constructs such as case ... esac, if ... fi from it. Though curiously a68's for .. do .. od became for .. do .. done! He even used some a68ish C macros so that his /bin/sh C code looked a bit like a68 code!
[Edit: a68 is a beautiful, consistent language in spite of being designed by a committee. Better than many that followed it.]
In a UNIX environment Steven Bourne ran into some parsing and/or other practical obstacles, for example when it came to implement for .. do .. od ...
It's in the slides (slide #29):
Unix group conversion
  • printing exit= after each command
  • od (octal dump) hence “done”

Also, in a A68 (compiler) setting there was the two-level van Wijngaarden grammar, not the most trivial one to parse.
However, ALGOL68 was designed by computer programming-language scientists, as opposed to SGML by Charles Goldfarb and others, IIRC Goldfarb's background was in linguistics.
 
for example when it came to implement for .. do .. od ...
It's in the slides (slide #29):
Good for him that there was no "done" command :)
Also, in a A68 (compiler) setting there was the two-level van Wijngaarden grammar, not the most trivial one to parse.
I believe a vW grammar wasn't strictly necessary for describing a68 and probably did more harm than good for the acceptance of a68. I learned it from books like Introductory Algol68 Programming by Brailsford and Walker that was quite practical. vW grammars can generate all langauges in the Chomsky hierarchy and more but....
 
Back
Top