There are two problems:
Replace first:
rh_reg="[rR]ed[:space:].*[Hh]at"
WITH
rh_reg="[rR]ed[[:space:]]*[Hh]at"
A character class such as [:space:] only works in square brackets. In addition, it seems that you want to combine zero or more spaces, and this is [[:space:]]* not [[:space:]].* . The latter will correspond to a space followed by zero or most.
Secondly, replace:
[ "$getos" =~ "$rh_reg" ]
WITH
[[ "$getos" =~ $rh_reg ]]
Regular expression matching requires the bash extended test: [[...]] . The standard POSIX test [...] does not have this feature. Also, in bash, regular expressions work only if they are not quotation marks.
Examples:
$ rh_reg='[rR]ed[[:space:]]*[Hh]at' $ getos="red Hat"; [[ "$getos" =~ $rh_reg ]] && getos="redhat"; echo $getos redhat $ getos="RedHat"; [[ "$getos" =~ $rh_reg ]] && getos="redhat"; echo $getos redhat
source share