From owner-freebsd-current Tue Feb 18 8: 2: 8 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3EDE237B401 for ; Tue, 18 Feb 2003 08:02:06 -0800 (PST) Received: from mail.rdslink.ro (mail.rdslink.ro [193.231.236.20]) by mx1.FreeBSD.org (Postfix) with SMTP id 21B8E43F93 for ; Tue, 18 Feb 2003 08:02:04 -0800 (PST) (envelope-from enache@rdslink.ro) Received: (qmail 14840 invoked from network); 18 Feb 2003 16:02:03 -0000 Received: from unknown (HELO ratsnest.hole) (10.100.0.68) by mail.rdslink.ro with SMTP; 18 Feb 2003 16:02:03 -0000 Received: from ratsnest.hole (localhost [127.0.0.1]) by ratsnest.hole (8.12.5/8.12.5) with ESMTP id h1IG1LHF001115; Tue, 18 Feb 2003 18:01:21 +0200 Received: (from adi@localhost) by ratsnest.hole (8.12.5/8.12.5/Submit) id h1IG1LH3001113; Tue, 18 Feb 2003 18:01:21 +0200 Date: Tue, 18 Feb 2003 18:01:20 +0200 From: Enache Adrian To: Poul-Henning Kamp Cc: current@freebsd.org Subject: Re: Shell programming 101: Is this an expr(1) bug ? Message-ID: <20030218160120.GA859@ratsnest.hole> References: <57374.1045568362@critter.freebsd.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57374.1045568362@critter.freebsd.dk> User-Agent: Mutt/1.4i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, Feb 18, 2003 at 12:39:22PM +0100, Poul-Henning Kamp wrote: > > > Running: > > #!/bin/sh > set -ex > > for p in ad2 ad0 ad1 > do > a0=`expr $p : '^ad\([0-9]\)$'` > done > > I get: > > syv# sh _ > + expr ad2 : ^ad\([0-9]\)$ > + a0=2 > + expr ad0 : ^ad\([0-9]\)$ > + a0=0 > syv# echo $? > 1 > syv# > > That looks like a bug to me... Confusing but documented behaviour: 1. expr ad0 : ad\([0-9]\) => expr 0 man expr If the match succeeds and the pattern contains at least one regu- lar expression subexpression ``\(...\)'', the string correspond- ing to ``\1'' is returned; otherwise the matching operator 2. `expr 0` => exit status = 1 man expr The expr utility exits with one of the following values: 0 the expression is neither an empty string nor 0. 1 the expression is an empty string or 0. This behaviour is the same on linux, *BSD and probably other systems too. Regards Adi To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message