From owner-freebsd-questions@freebsd.org Mon Sep 28 13:12:29 2015 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1F71AA0BC05 for ; Mon, 28 Sep 2015 13:12:29 +0000 (UTC) (envelope-from milios@ccsys.com) Received: from cargobay.net (cargobay.net [198.178.123.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F2615111E for ; Mon, 28 Sep 2015 13:12:28 +0000 (UTC) (envelope-from milios@ccsys.com) Received: from [192.168.0.14] (cblmdm72-240-160-19.buckeyecom.net [72.240.160.19]) by cargobay.net (Postfix) with ESMTPSA id 7805B27; Mon, 28 Sep 2015 13:06:14 +0000 (UTC) Subject: Re: 10.2-RELEASE/amd64: grep regex syntax vs. grep-bug To: "no@spam@mgEDV.net" , freebsd-questions@freebsd.org References: <00e801d0f9e2$125ec430$371c4c90$@mgedv.net> From: "Chad J. Milios" Message-ID: <56093CB4.6060606@ccsys.com> Date: Mon, 28 Sep 2015 09:12:20 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <00e801d0f9e2$125ec430$371c4c90$@mgedv.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2015 13:12:29 -0000 On 9/28/2015 7:37 AM, no@spam@mgEDV.net wrote: > hi folks, > the goal: grep, that a variable contains a number and JUST digits. > # setup sample variable - we're on /bin/sh @ 10.2-RELEASE/amd64. > x="" > # od output the content of the variable to ensure content > echo "$x" | od -ctdC > 0000000 \n > 10 > 0000001 > # now try /usr/bin/grep'pin (C locale) that it contains... > # ^ at BOL... > # [0-9] require a digit > # * ... and digits following > # $ ...until we reach EOL > # ... but...: > echo "$x" | grep -c '^[0-9]*$' > 1 <== WHY? > it works if i remove the *, but this would only work for 1digit nrs. > is this a grep bug or my false understanding of how '*' works? > you want to use + (1 or more) instead of * (0 or more) and for that youll need to add -E mode to grep as well