Re: process result code in if

2013-06-07 Thread A.P. Horst
On 7-6-2013 5:13, Miles Bader wrote: Gary V. Vaughan g...@gnu.org writes: On 7 Jun 2013, at 08:41, Miles Bader mi...@gnu.org wrote: Wait, why can't you use test $x -gt 0...? You mean test 0 -lt $x, otherwise if x starts with a hyphen (e.g -1) things will go awry! I dunno, test here (both

Re: process result code in if

2013-06-07 Thread Miles Bader
A.P. Horst arieho...@xs4all.nl writes: I ended up using this: if ! test $var -gt 0 /dev/null 21; then Incidentally, test should never produce any output on stdout, so you can just use 2/dev/null instead of /dev/null 21... :] -miles -- P.S. All information contained in the above letter is

Re: process result code in if

2013-06-07 Thread Tim Rice
On Fri, 7 Jun 2013, A.P. Horst wrote: Thanks for all the great input! Seems google isn't always your best friend, at least not when it comes to autoconf. The solution with the test command is very elegant and readable. I ended up using this: if ! test $var -gt 0 /dev/null 21; then not

Re: process result code in if

2013-06-07 Thread Andres Perera
On Thu, Jun 6, 2013 at 8:11 AM, Eric Blake ebl...@redhat.com wrote: - Original Message - A more robust, (and more portable), formulation may be: echo $var | grep '^+\{0,1\}[0-9]\{1,\}$' /dev/null 21 Why fork, when straight shell will do? yea, forking for grep is probably going

Re: process result code in if

2013-06-07 Thread Miles Bader
Tim Rice t...@multitalents.net writes: On Fri, 7 Jun 2013, A.P. Horst wrote: if ! test $var -gt 0 /dev/null 21; then if ! test ... is definitely not portable. Hmmm, I can never remember which is the portable one, but from the autoconf docs, one should usually use if test ! ... instead :

process result code in if

2013-06-06 Thread A.P. Horst
Hi, I am trying to do a simple check to validate a value is a positive integer. There are many variations to do this but in general this should do the trick: var=100 if echo $var | grep -Eq '^[0-9]+$' /dev/null 21; then echo positive integer else echo something else fi if I put this

Re: process result code in if

2013-06-06 Thread Earnie Boyd
On Thu, Jun 6, 2013 at 5:00 AM, A.P. Horst wrote: Also when I just have: echo $var | grep -Eq '^[0-9]+$' echo $? --8-- I am on a win7 x64 machine with MinGW 3.20 and W32API 3.17 sh --version GNU bash, version 3.1.17(1)-release (i686-pc-msys) How is the var variable set? If you're using the

Re: process result code in if

2013-06-06 Thread Keith Marshall
On 6 June 2013 12:12, Earnie Boyd wrote: On Thu, Jun 6, 2013 at 5:00 AM, A.P. Horst wrote: Also when I just have: echo $var | grep -Eq '^[0-9]+$' echo $? --8-- I am on a win7 x64 machine with MinGW 3.20 and W32API 3.17 sh --version GNU bash, version 3.1.17(1)-release (i686-pc-msys)

Re: process result code in if

2013-06-06 Thread Eric Blake
- Original Message - A more robust, (and more portable), formulation may be: echo $var | grep '^+\{0,1\}[0-9]\{1,\}$' /dev/null 21 Why fork, when straight shell will do? case $var in +*) tmp=$var ;; *) tmp=+$var ;; esac case $tmp in +*[!0-9]* | +) echo not numeric ;; *)

Re: process result code in if

2013-06-06 Thread Keith Marshall
On 6 June 2013 13:41, Eric Blake wrote: A more robust, (and more portable), formulation may be: echo $var | grep '^+\{0,1\}[0-9]\{1,\}$' /dev/null 21 Why fork, when straight shell will do? case $var in ... Agreed, avoiding the fork is a good idea, and I do often use case

Re: process result code in if

2013-06-06 Thread Miles Bader
Wait, why can't you use test $x -gt 0...? -miles -- Logic, n. The art of thinking and reasoning in strict accordance with the limitations and incapacities of the human misunderstanding. ___ Autoconf mailing list Autoconf@gnu.org

Re: process result code in if

2013-06-06 Thread Gary V. Vaughan
On 7 Jun 2013, at 08:41, Miles Bader mi...@gnu.org wrote: Wait, why can't you use test $x -gt 0...? You mean test 0 -lt $x, otherwise if x starts with a hyphen (e.g -1) things will go awry! Cheers, -- Gary V. Vaughan (gary AT gnu DOT org) ___

Re: process result code in if

2013-06-06 Thread Miles Bader
Gary V. Vaughan g...@gnu.org writes: On 7 Jun 2013, at 08:41, Miles Bader mi...@gnu.org wrote: Wait, why can't you use test $x -gt 0...? You mean test 0 -lt $x, otherwise if x starts with a hyphen (e.g -1) things will go awry! I dunno, test here (both coreutils test, and the bash builtin)