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!)
 
Back
Top