As an alternative one could use this for number detection:
if ! echo $port | grep -Eq '^\-?[0-9]*$' ; then
Advantages:
* more obvious match of exact *type* of number expected (integers only with optional leading minus)
* no redirect of errors to /dev/null (in case something else goes wrong not involving the failure you're trying to trigger)
As an alternative one could use this for number detection:
if ! echo $port | grep -Eq '^\-?[0-9]*$' ; then
Advantages:
* more obvious match of exact *type* of number expected (integers only with optional leading minus)
* no redirect of errors to /dev/null (in case something else goes wrong not involving the failure you're trying to trigger)