What do you have to be aware of in the following conditional?
if [[ 4 > 4 ]]
Answer:
This is a string comparison and will not evaluate 4 as an integer. The > symbol will be comparing ASCII values of the character 4, not the integer value.
To compare integer equality in an if conditional you should use if [[ 4 -eq 4 ]]. The > operator is for string comparisons.
No comments:
Post a Comment