bash: testing if string is a number

How do you test if a string is a number?

Trying to do something like this:

x="AS"
if( x is not a number ); then
x=0
fi

Because I want to do number arithmetic with x.

ok I guess it's an error if it's not numeric.

Why not :

typeset -i x before assigning it?

Below I write a code with tow output the first one is to numeric arguments and the second if it isn�t numeric

#!/bin/bash
if echo $1 | grep "^[0-9]*$">aux
then
  echo "La cadena es un valor numerico."
else
  echo "La cadena no es un valor numerico."
fi
rm aux

Enjoy that, and please correct my english :wink:

If only you had searched the forums.... :frowning:

How to check whether a string is number or not