Have $int in quotes, to prevent unwanted expansions.
The ? and + repeaters are defined in ERE only, that is egrep or grep -E
Code:
if egrep -q '^-?[0-9]+$' <<< "$int"
If your shell does not have the <<< operator, the following is equivalent
Code:
if echo "$int" | egrep -q '^-?[0-9]+$'
expr does BRE like grep. A fix is to emulate the ? and + with \{m,n\}.
Further, expr is vulnerable e.g. if $int contains an expr operator like ":".
A fix is to prepend a simple character, here X, on both sides of the : operator.
Code:
if expr X"$int" : X'-\{0,1\}[0-9]\{1,\}'
The BRE after the : operator works from the beginning so the ^ can be omitted.