Hello,
I'm not sure whether I found a bug in Bash or in it's documentation.
The documentation suggests that the arithmetic binary operator '-eq' is
for integers ("Arg1 and arg2 may be positive or negative integers."),
but when using it with '[[ ]]' it doesn't fail on strings.
$ [[ 1 -eq 1 ]] && echo "yes" || echo "no"
yes
$ [[ "x" -eq "x" ]] && echo "yes" || echo "no"
yes
as opposed to `test':
$ test "x" -eq "x" && echo "yes" || echo "no"
test: invalid integer 'x'
no
$ [ "x" -eq "x" ] && echo "yes" || echo "no"
[: invalid integer 'x'
no
If this is expected behaviour, I think the documentation should reflect
this.
Use case: I use this to test whether a variable is an integer.
$ [ "${x}" -eq "${x}" ] 2> /dev/null && echo "yes" || echo "no"
...
Looking a bit further: it doesn't do any comparison on the given strings:
$ [[ "x" -eq "y" ]] && echo "yes" || echo "no"
yes
$ [[ "x" -eq "yz" ]] && echo "yes" || echo "no"
yes
but it does on integers:
$ [[ 1 -eq 2 ]] && echo "yes" || echo "no"
no
Kind regards,
Rob
--
-- Rob la Lau
--
-- Sysadmin en webdeveloper in ruste
--
-- web : https://ohreally.nl/
-- eml : [email protected]
--