I need to compare two strings and ignoring the case of the contents.
IF [ $first != $second ]. Anything I can add to this command so that the comparison ignores the case.
Ubuntu – Command to compare two strings
bashcommand linescripts
bashcommand linescripts
I need to compare two strings and ignoring the case of the contents.
IF [ $first != $second ]. Anything I can add to this command so that the comparison ignores the case.
Best Answer
In bash, you can perform case conversions easily e.g. if
var="vAlUe"
thenwhile
You can use this to make you comparison case-insensitive by converting both arguments to the same case, i.e.
or
Another approach is to use the bash
nocasematch
option (thanks @Tshilidzi_Mudau), although this appears to work only with the[[ ... ]]
extended test operator:but