Compare Strings Case-Insensitively in Bash
Compare strings ignoring case by lowercasing both sides with the comma form of expansion, or switch on shopt nocasematch, which also affects case and the =~ operator.
Two strings differ only in letter case and you want them treated as equal.
a=Hello b=hELLO
[[ $a == "$b" ]] || echo "plain compare: different"
[[ ${a,,} == "${b,,}" ]] && echo "lowercased compare: equal"
shopt -s nocasematch
[[ $a == "$b" ]] && echo "nocasematch: equal"
case $a in hello) echo "case honors nocasematch too" ;; esac
[[ $a =~ ^HELLO$ ]] && echo "so does =~"
shopt -u nocasematch
[[ $a == "$b" ]] || echo "switched off again: different"plain compare: different
lowercased compare: equal
nocasematch: equal
case honors nocasematch too
so does =~
switched off again: differentLowercasing both values with ${a,,} and comparing the results works in any Bash 4 or later script and changes nothing else. shopt -s nocasematch makes the shell ignore case in [[ == ]], [[ =~ ]] and case patterns until it is switched off again, which the run confirms for all three. Both are described in The Shopt Builtin and in the parameter expansion section of the manual.
nocasematch is a global switch, so turn it off afterward or set it inside a subshell, or later comparisons in the script change meaning silently. Case conversion with the comma operators needs Bash 4.0, and the result for non-ASCII letters depends on the locale.