From owner-freebsd-bugs@FreeBSD.ORG Fri Nov 11 15:50:11 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18A8B1065675 for ; Fri, 11 Nov 2011 15:50:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 084498FC18 for ; Fri, 11 Nov 2011 15:50:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id pABFoAdL017465 for ; Fri, 11 Nov 2011 15:50:10 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id pABFoAqS017464; Fri, 11 Nov 2011 15:50:10 GMT (envelope-from gnats) Date: Fri, 11 Nov 2011 15:50:10 GMT Message-Id: <201111111550.pABFoAqS017464@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/162468: expr(1) false syntax errors X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2011 15:50:11 -0000 The following reply was made to PR bin/162468; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, egrosbein@rdtc.ru Cc: Subject: Re: bin/162468: expr(1) false syntax errors Date: Fri, 11 Nov 2011 16:44:55 +0100 > [expr treats any string that looks like an operator as an operator, > for example, expr '>' : '.*' fails] The current behaviour of expr is allowed by POSIX (SUSv4, XCU 4 Utilities, expr). If the application passes '>', this is not a string operand but an operator, even if that results in an invalid expression. This is also documented in the man page. It would be a valid extension to allow such expressions but it is not immediately clear how it would work. For example, should expr \( = \) compare two strings ("0") or return a single string ("=")? And should expr \( + \) return "+" or raise an error? The test utility is different in that POSIX specifies how a similar ambiguity shall be resolved (for a limited set of cases). Oh, and if you want to find a string length in a shell script, why don't you just use ${#VAR} (given that the string is in $VAR)? If you must use expr(1), do expr \( "x$VAR" : '.*' \) - 1 as described in the man page. -- Jilles Tjoelker