Fun with Bash Double Brackets, Regular Expressions, Case Matching, and Digits
After some quick searching and not finding the answer, I decided to write this up for my own reference. My original inquiry was how do I form a double-bracketed if branch statement, using "=~" to check a variable against a regular expression for upper OR lower case of a specific search string in bash. After some working it out, I think I got it. See below. For instance, in the example script below, the user is asked to answer yes or no, the value entered is then checked to "loosely" match a predefined value. In this case, yes/y (with any combination of case) will match the Regular Expression. This example points out how to formulate your bracketed regular expression to match any variations in case (or even a single character answer, e.g., y OR n). There are differences with the bracketed use of regular expressions compared to how grep uses them, I'm finding. Like, notice in the experimental script below, how single quotes are not used in the bracketed ...