Compare string (capitol letters) abc to ABC
I want compare two strings
if [ "$string1" == "$string2" ] ... It works. But I want to compare without distinction between "abc" and "ABC". I mean... ¿abc = ABC? YEs!!!! ¿aBc = ABC? Yes !!!!. How can i change a expresión to capitol letters. :-) |
If you're using bash v.4, it's easy. It has some new parameter substitution rules for case conversion.
Code:
$ string1="FoObAr" Code:
$ declare -u string1="FoObAr" Code:
string1="$(echo $string1 | tr [a-z][A-Z])" # converts string to uppercase And of course, if you want to keep the original strings intact, then create two new variables and test them instead. |
To change a string to uppercase (or lowercase) you can use translate (abbreviated as tr). For example:
echo 'linux' | tr "a-z" "A-Z" will give the output: LINUX so tr "variable" "range 1" "range 2" takes everything it finds in variable from range 1 and translates it to its partner in range 2. I haven't used it in the context your describing before but it should work ok. Hope this helps, Luke. |
Quote:
Code:
echo 'linux' | LC_ALL=C tr 'A-Z' 'a-z' |
Interesting stuff. Thanks :-)
Luke. |
All times are GMT -5. The time now is 07:17 PM. |