autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: process result code in if


From: Eric Blake
Subject: Re: process result code in if
Date: Thu, 6 Jun 2013 08:41:23 -0400 (EDT)

----- Original Message -----

> 
> A more robust, (and more portable), formulation may be:
> 
>   echo $var | grep '^+\{0,1\}[0-9]\{1,\}$' > /dev/null 2>&1

Why fork, when straight shell will do?

case $var in
  +*) tmp=$var ;;
  *) tmp=+$var ;;
esac
case $tmp in
  +*[!0-9]* | +) echo "not numeric" ;;
  *) echo integer ;;
esac

Again, when placing this in autoconf.ac, you need to quote the
[0-9] since m4 eats one level of [], either by writing [[0-9]]
in place, or by using [] around the entire case snippet.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]