#!/usr/bin/env bash

is_number() {

   return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);

   # - also possible
   # -
   #[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
   #return $([[ ! -z "${1##*[!0-9]*}" ]])
}

is_int() {
   return $(test "$@" -eq "$@" > /dev/null 2>&1);
}

_int=-5
_number=5
_no_number=5a

echo -e "\nTest of valid number (positiv integer)"
if is_number $_number ; then
   echo -e "\t$_number is a number"
else
   echo -e "\t$_number is NOT a number"
fi
if is_number $_int ; then
   echo -e "\t$_int is a number"
else
   echo -e "\t$_int is NOT a number"
fi
if is_number $_no_number ; then
   echo -e "\t$_no_number is a number"
else
   echo -e "\t$_no_number is NOT a number"
fi


echo -e "\nTest of valid integer"
if is_int $_number ; then
   echo -e "\t$_number is a valid integer"
else
   echo -e "\t$_number is NOT a valid integer"
fi
if is_int $_int ; then
   echo -e "\t$_int is a valid integer"
else
   echo -e "\t$_int is NOT a valid integer"
fi
if is_int $_no_number ; then
   echo -e "\t$_no_number is a valid integer"
else
   echo -e "\t$_no_number is NOT a valid integer"
fi

echo ""
exit 0
