3 ms·
Can you give an example where = would be unsuitable for comparison of numbers?
by usr1106 2y ago
Can you give an example where = would be unsuitable for comparison of numbers?
- woodruffw 2y agoHere's a trivial one: $ [[ 0xFF -eq 255 ]] ; echo $? 0 $ [[ 0xFF = 255 ]] ; echo $? 1
- usr1106 2y agoOh, hex. Another bashism. Not sure when I would have needed that in a shell script last time. So in most cases just using [ solves the problem. If you want to use hex from untrusted user input you need to validate the input first. Yes, the bash programmer needs to be aware of many pitfalls. I wasn't, but I would call myself more a bash avoider than a bash programmer. Yes, I use bash for interactive use, talking only about scripting.