Check input consists only of numeric characters in shell script -
i need check input consists of numeric characters. have code below, didn't work properly.
if [[ $1 =~ [0-9] ]]; echo "invalid input" fi it should give true 678686 not yy66666.
how this:-
re='^[0-9]+$' if ! [[ $number =~ $re ]] ; echo "error: invalid input" >&2; exit 1 fi or
case $number in ''|*[!0-9]*) echo nonnumeric;; *) echo numeric;; esac
Comments
Post a Comment