I am writing a script in bash which will prompt the user for two inputs. These inputs are assigned to the variables 'TO_SCHEMA' and 'FROM_SCHEMA' respectively.
I need a way to verify proper input. My requirements are as follows:
Each variable will have 3 acceptable values. They are the same values for both variables, but both variables must be in this list of three, and they cannot be the same value.
So if the values are 'myco', 'myco_int', and 'teambatch', then both variables must be one of those values, but they can't be the same.
${TO_SCHEMA} = myco && ${FROM_SCHEMA} = myco_int
Pass
${TO_SCHEMA} = myco_int && ${FROM_SCHEMA} = myco_int
Fail
${TO_SCHEMA} = mco && ${FROM_SCHEMA} = myco_int
Fail
${TO_SCHEMA} = myco && ${FROM_SCHEMA} = donkey
Fail
How can I accomplish this?
I began with an if statement full of AND and OR operators, but they got ugly fast. My experience with regex is limited, and my experience with sed and awk is non-existent, but I'm willing to learn and try any of that. Any help would be appreciated.
EDIT:
I should also mention that this script is just for a somewhat small tedious one off task I have to do a lot at work that I would love to automate. If I'm not the one using it, then someone on my team will be. So this input checking is a want and not a need. It's not the end of the world if the script breaks because of bad input. I would just like it to handle bad input more elegantly.
EDIT AGAIN: I appreciate everyone's suggestions, but I have to make some clarifications. The values won't actually be schema 1,2 and 3. I'm not allowed to provide proper names for security reasons, but I'm changing them to values more similar to the real ones.
[[ $TO_SCHEMA != $FROM_SCHEMA && $TO_SCHEMA =~ ^schema(1|2|3)$ && $FROM_SCHEMA =~ ^schema(1|2|3)$ ]]