I have a simple hostname check in a bash script:
if [[ `hostname` -eq "cps1214" ]]
then
JAVA_HOME=/usr/local/jdk1.6.0_21
fi
On our old SuSE 8 system this works fine. On our newer CentOS system this causes an error:
[[: dev.example.com: syntax error: invalid arithmetic operator (error token is ".example.com")
I'm not really sure what the issue is here. My understanding is that -eq is explicitly for string comparisons, hostname is clearly returning a string, and the right-hand side is also a string. Why is it complaining about arithmetic?
-eqis specifically for numeric comparison, not strings.