Problem
I have to compare a string "problem1.sh" with itself. It works fine in case of solution1.sh (given below) where I have used square brackets for comparison. However, it does not work in case of solution2.sh (given below) where I have used round brackets. It shows the mentioned error (given below).
What I have tried?
I have tried to learn the difference between the use of square and round brackets in bash script from here and here. I understand that ((expression)) is used for comparison arithmetic values, not for the string values.
So, what does create the problem?
If I remove sub-string ".sh" from the string "problem1.sh" and compare using the same statement if (("problem1" == "problem1")), it works fine. However, when I just add "." in the string, it creates the problem. Even if I remove everything except "." from the string and use the statement if (("." == ".")), it shows me error.
Then, my question
If the statement if (("problem1" == "problem1")) can work fine (may be, it will work fine for every letter of English alphabet), why does "." string create the problem? I mean, Why we can not compare "." using round brackets in if statement of bash script (e.g if (("." == "."))) when we can compare letters using the same expression (e.g if (("findError" == "findError"))) ?
solution1.sh
if [ "problem1.sh" == "problem1.sh" ]
then
printf "Okay"
fi
solution2.sh
if (( "problem1.sh" == "problem1.sh" ))
then
printf "Okay"
fi
Error Message For solution2.sh
./solution2.sh: line 1: ((: problem1.sh == problem1.sh : syntax error:
invalid arithmetic operator (error token is ".sh == problem1.sh ")