From owner-freebsd-bugs Fri Jun 11 10:10: 5 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id CB96314F5D for ; Fri, 11 Jun 1999 10:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id KAA90429; Fri, 11 Jun 1999 10:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from misha.cisco.com (misha.cisco.com [171.69.206.50]) by hub.freebsd.org (Postfix) with ESMTP id 6976C14CB5 for ; Fri, 11 Jun 1999 10:08:32 -0700 (PDT) (envelope-from mi@misha.cisco.com) Received: (from mi@localhost) by misha.cisco.com (8.9.3/8.9.1) id NAA57393; Fri, 11 Jun 1999 13:08:31 -0400 (EDT) (envelope-from mi) Message-Id: <199906111708.NAA57393@misha.cisco.com> Date: Fri, 11 Jun 1999 13:08:31 -0400 (EDT) From: Mikhail Teterin Reply-To: mi@aldan.algebra.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/12137: something wrong with shell -- functions with arithm expressions Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 12137 >Category: bin >Synopsis: something wrong with shell -- functions with arithm expressions >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jun 11 10:10:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Mikhail Teterin >Release: FreeBSD 3.2-STABLE i386 >Organization: Virtual Estates, Inc. >Environment: >Description: This strange method of figuring out the length of a string gives different results for the strings of the same length depending on their content: length () { echo $((0 + ${#1})) } length "abc (def [xyz])" length "abc (def (xyz))" The use of ``[]'' makes the string appear one character longer. I made the severity and priority fairly high, because this may indicate some brokenness in more important parts of sh. A more simple attempt to reproduce this: a="abc (def [xyz])" echo $((0+${#a})) b="abc (def (xyz))" echo $((0+${#b})) works as expected -- same length for both strings. So does: length () { echo ${#1} } length "abc (def [xyz])" length "abc (def (xyz))" You actually need the combination of arithmetic and function, it seems. >How-To-Repeat: Just run the script above with sh. I see: 16 15 >Fix: Use bash or ksh -- they both produce 15 for both of this lines. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message