case - string testing structure.

case that perform an if, else if, ..., else test sequence on 
a provided string.

case uses the file-name wild-card metacharacters to describe a
match template to compare a provide string against. If matched, a block
of specified actions are then executed.

case general structure


  • case - keyword starting case structure.
  • "$var" - variable containing string to be tested. Usually quoted so a null string does not crash case statement.
  • in - keyword closes the line specifying the target string.
  • str_template-1 - string pattern to match against. Match is exact. Wild cards and alternative matches used to create a more general match pattern.
  • ) - right parenthesis indicates close of a match statement.
  • action_cmd[s] - action[s] to take if variable contents matches string pattern. This can be a whole block of bash code including other case statements Or even invoke other programs.
  • ;; - double semi-colon, indicates end of particular action block.
  • esac - keyword that terminates the case structure. case features and properties Template match patterns and wild-cards
  • The str_template supports wild-cards modeled after the filename wild-cards.
    These can be combined in any order or repetition. Just remember 1st match is
    only match, so work from specific to general.