.sh check for numeric content
Anh Ky Huynh
xkyanh at gmail.com
Thu Jun 24 02:20:50 UTC 2010
On Thu, 24 Jun 2010 09:24:39 +0800
Aiza <aiza21 at comclark.com> wrote:
> Receiving a variable from the command line that is suppose
> to contain numeric values.
>
> How do I code a test to verify the content is numeric?
echo "$your_variable" | grep -E "^[0-9]+(\.[0-9]*)*[0-9]+$"
If $your_variable is numeric (123, or 123.123, etc), the return code should be 0. You can custom to script to support negative numbers.
--
Anh Ky Huynh
More information about the freebsd-questions
mailing list