arg1 -eq arg2 (conditional operator)

true if integer arg1 has the same value as integer arg2.

Please note, that strings are compared by = or ==.

Examples

Different ways to test two integers for equality:
1
2
3
4
test "$n" -eq 42 && echo "the answer is $n"
[ "$n" -eq 42 ] && echo "the answer is $n"
# Bash
[[ "$n" -eq 42 ]] && echo "the answer is $n"
BashSupport Pro is a Bash IDE with support for -eqtry it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal