We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Yes, the chart is incorrect. man test shows the correct operators.
Technically, = is for strings, and -eq is for integers. Using = on integers compares them as strings, since bash is weakly typed. Often this won't have much of an impact, but you can see the difference by testing [ 0 = 00 ] vs [ 0 -eq 00 ].
Best practice is to use the correct operator so that when you hit the weird edge cases, you don't lose hair looking for a hard-to-find bug.
More on Conditionals
You are viewing a single comment's thread. Return to all comments →
Yes, the chart is incorrect.
man test
shows the correct operators.Technically,
=
is for strings, and-eq
is for integers. Using=
on integers compares them as strings, since bash is weakly typed. Often this won't have much of an impact, but you can see the difference by testing[ 0 = 00 ]
vs[ 0 -eq 00 ]
.Best practice is to use the correct operator so that when you hit the weird edge cases, you don't lose hair looking for a hard-to-find bug.