[olug] Test for integer in bash

John Hobbs john at velvetcache.org
Thu Nov 29 05:28:56 UTC 2007


Thanks, I can't believe I didn't think of just adding one required one
in front of the optional ones.

Also, I got the + version and the "{1,}" structure working, I had to
use the "extended" regular expressions flag, -E.

FYI I have GNU grep 2.5.3.

Thanks again!

- John

On 11/28/07, Obi-Wan <obiwan at jedi.com> wrote:
> >   echo "$1" | grep ^[0-9]*$ > /dev/null
> >
> > testInt
> >
> > Secondly, I'm sure you've noticed that the last test of nothing
> > returns as a match.  Why can't I get the correct regex,  echo 900 |
> > grep ^[0-9]+$  , to work?  echo 900 | grep ^[0-9]{1,}$ fails too.
>
> In your last example, you're trying to use perl regex, which doesn't
> work in grep (or even egrep).  What you want is "grep "^[0-9][0-9]*$".
>
> --
> Ben "Obi-Wan" Hollingsworth                             obiwan at jedi.com
>    The stuff of earth competes for the allegiance I owe only to the
>      Giver of all good things, so if I stand, let me stand on the
>        promise that You will pull me through.  -- Rich Mullins
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>



More information about the OLUG mailing list