I want to compare 2 strings with ignore case in bash shell. Suppose, if [ "test" = "TEst" ] ... should be true and enter into if loop. Solution: Please try this: if [ `echo "TeSt" | tr -s '[:upper:]' '[:lower:]` = `echo
"Test" | tr -s '[:upper:]' '[:lower:]` ]
or Try similar, it still worked. input=TESt
if [[ "$input" =~ "test" ]]; then
Note: Do be aware in the 2nd example above, that, in the bash shell, the =~ is a binary operator, and everything to the right is a regular expression. Strictly speaking, it is not an equality check, but a matching operator? This string would also be "equal" in your script above: input="myTEStube"
Have a Linux Problem
Linux Books
Linux Home: Linux System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|