Case insensitive comparison of strings in shell script

Sachin Chourasiya picture Sachin Chourasiya · Nov 13, 2009 · Viewed 197.7k times · Source

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Answer

alphaniner picture alphaniner · Oct 16, 2013

In Bash, you can use parameter expansion to modify a string to all lower-/upper-case:

var1=TesT
var2=tEst

echo ${var1,,} ${var2,,}
echo ${var1^^} ${var2^^}