The following program checks if the first parameter is a number, or a not a number. The best I could come up with so far is:
#/bin/bash
if (( $# )) && (( $1 != 0 )) ; then
echo "number"
else
echo "not number"
fi
This works for numbers like
1,-1,100, etc, for stringsa,abc,a431, or if no parameter is given.It works with a warning for strings like
1a1,1.3,-1.2But FAILS (obviously) if the parameter is
0
How could this be fixed? (using arithmetic expressions)
Related: Bash integer comparison