Check parameter is number or string

Hey I'm new in linux,

I'm looking for a code to check whether the parameter is a number or a string.

I have already tried this code:

eerste=$(echo $1 | grep "^[0-9]*$">aux)
if [ eerste ]

But it doesn't work.:confused:
Thanks

Try:

if [ $(echo $1 | egrep "^[0-9]+$") ]

That's actually a poor solution. Should the value being tested expand to multiple fields, it could lead to syntax errors or other forms of unexpected behavior.

You could quote the command substitution, to ensure that test/[ is only passed a single argument, but, if using grep anyway, I would drop the use of test/[ altogether, redirect the output of egrep to /dev/null (or use the -q option if available), and allow the if statement to use egrep's exit status directly.

---------- Post updated at 03:02 PM ---------- Previous update was at 02:58 PM ----------

A different approach:

case $1 in
    *[!0-9]*)  echo Error. Not a number.;;
           *)  echo OK. ;;
esac

Regards,
Alister