I\'m trying to write a comparison in a while statement that\'s case insensitive. Basically, I\'m simply trying to shorten the following to act on a yes or no question promp
shopt -s nocasematch
while [[ $yn == y || $yn == "yes" ]] ; do
or :
shopt -s nocasematch
while [[ $yn =~ (y|yes) ]] ; do
[[
is a bash keyword similar to (but more powerful than) the [
command. See http://mywiki.wooledge.org/BashFAQ/031 and http://mywiki.wooledge.org/BashGuide/TestsAndConditionals[[
.=~
operator of [[
evaluates the left hand string against the right hand extended regular expression (ERE). After a successful match, BASH_REMATCH
can be used to expand matched groups from the pattern. Quoted parts of the regex become literal. To be safe & compatible, put the regex in a parameter and do [[ $string =~ $regex ]]