[Top][All Lists]

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

Re: process result code in if

From: Keith Marshall
Subject: Re: process result code in if
Date: Thu, 6 Jun 2013 13:21:28 +0100

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
>> program, I'm guessing the issue is CRLF versus just LF.  ...
> Another (more likely) possibility is that the shell fragment is under
> quoted, where it appears in ...

 BTW, even when you've corrected the under quoting issue, this

  echo $var | grep -Eq '^[0-9]+$'

test that $var represents a positive integer doesn't really "cut the
mustard"; there are two reasons:

1) It completely neglects to consider any initial unary + sign, so
   would reject any representation such as var=+50

2) grep -Eq ... is not portable; not all implementations of grep support
   GNU grep's -E and -q options.

A more robust, (and more portable), formulation may be:

  echo $var | grep '^+\{0,1\}[0-9]\{1,\}$' > /dev/null 2>&1


reply via email to

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