Re: process result code in if

2013-06-07 Thread Miles Bader
Tim Rice writes: > On Fri, 7 Jun 2013, A.P. Horst wrote: >> if ! test $var -gt 0 > /dev/null 2>&1; 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 : It is s

Re: process result code in if

2013-06-07 Thread Andres Perera
On Thu, Jun 6, 2013 at 8:11 AM, Eric Blake wrote: > - 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? yea, forking for grep is probably going to

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 2>&1; then >

Re: process result code in if

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

Re: process result code in if

2013-06-06 Thread A.P. Horst
On 7-6-2013 5:13, Miles Bader wrote: "Gary V. Vaughan" writes: On 7 Jun 2013, at 08:41, Miles Bader 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 th

Re: process result code in if

2013-06-06 Thread Miles Bader
"Gary V. Vaughan" writes: > On 7 Jun 2013, at 08:41, Miles Bader 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) seems to handle

Re: process result code in if

2013-06-06 Thread Gary V. Vaughan
On 7 Jun 2013, at 08:41, Miles Bader 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) ___ Autoconf maili

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 https://lists.gnu.or

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 2>&1 > > Why fork, when straight shell will do? > > case $var in > ... > Agreed, avoiding the fork is a good idea, and I do often us

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 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"

Re: process result code in if

2013-06-06 Thread Keith Marshall
On 6 June 2013 12:54, Keith Marshall wrote: > 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]+$' >> > ... >> >> How is the var variable set? If you're using the output of a compiled >>

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)-relea

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

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 2>&1; then echo "positive integer" else echo "something else" fi if I