Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jun 2010 12:31:13 +0200
From:      Thomas <fwd@gothschlampen.com>
To:        Aiza <aiza21@comclark.com>
Cc:        questions@freebsd.org
Subject:   Re: .sh  check for numeric content
Message-ID:  <20100624103113.GA27123@gothschlampen.com>
In-Reply-To: <4C22E4A0.1040206@comclark.com>
References:  <4C22B3D7.6070102@comclark.com> <20100624013755.GA5009@gothschlampen.com> <4C22C816.3000105@comclark.com> <4C22E4A0.1040206@comclark.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jun 24, 2010 at 12:52:48PM +0800, Aiza wrote:

Hello,

> But when I tried this format
> [ expr "${dup_times}" : "[0-9]*$" ] || echo "value is not numeric"
> 
> I get the error message no mater what the value is.
> 
> What am I doing wrong?

Even if "[" at first glance seems like a special syntax of the shell,
it really is just an alternative name or way of calling test(1):

$ ls -l $(which test [)
-rwxr-xr-x 1 root root 42584 2009-10-06 13:07 /usr/bin/[
-rwxr-xr-x 1 root root 30284 2009-10-06 13:07 /usr/bin/test

(this actually is from a Linux system)

You can read about the checks test(1) can perform and its syntax in its
manual page. It will give you a nice and concise overview of what can be
archived in this "[ $EXPRESSION ]" syntax, and what checks are left to
be performed in other ways. Hope this helps.

Regards,
Thomas



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100624103113.GA27123>