The == is used to compare two string in shell script, however I want to compare two strings by ignoring case, how it can be done.Do we any standard command for this.
No manual entry for shopt.Its not available on my system
Sachin Chourasiya
2009-11-13 11:41:34
nocasematch for strings.
ghostdog74
2009-11-13 11:57:45
@ghostdog, I like the tone
Sachin Chourasiya
2009-11-13 12:39:18
A:
One way would be to convert both strings to upper or lower:
test $(echo "string" | /bin/tr -s '[:upper:]' '[:lower:]') = $(echo "String" | /bin/tr -s '[:upper:]' '[:lower:]') && echo same || echo different
Another way would be to use grep:
echo "string" | grep -qi '^String$' && echo same || echo different
Randy Proctor
2009-11-13 11:52:35
A:
if you have bash
str1="MATCH"
str2="match"
shopt -s nocasematch
case "$str1" in
$str2 ) echo "match";;
*) echo "no match";;
esac
otherwise, you should tell us what shell you are using.
alternative, using awk
str1="MATCH"
str2="match"
awk -vs1="$str1" -vs2="$str2" 'BEGIN {
if ( tolower(s1) == tolower(s2) ){
print "match"
}
}'
ghostdog74
2009-11-13 12:02:47
A:
var1=match
var2=MATCH
if echo $var1 | grep -i "^${var2}$" > /dev/null ; then
echo "MATCH"
fi
Larry
2010-04-27 20:00:23