I've been trying to figure out a way to test if a parameter is a number using the command expr.
In my script so far I've written:
expr $1 + 1 2>/dev/null
if [ $? -eq 2 -o $1 -lt 0 ]
then
echo "$1 is not a positive integer" >&2
exit 1
fi
What I'm trying to do here is to add 1 to the variable. If this provokes an error (which means that the variable isn't a number), the result will be sent to /dev/null. After, I test if the return code is 2 or if the variable is less than 0. However this doesn't seem to work... any ideas?
P.S. Please keep in mind that I must use expr