From owner-freebsd-questions@FreeBSD.ORG Tue Jun 5 17:32:43 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07AA2106564A for ; Tue, 5 Jun 2012 17:32:43 +0000 (UTC) (envelope-from bsd-unix@embarqmail.com) Received: from mailrelay.embarq.synacor.com (mailrelay.embarq.synacor.com [208.47.184.3]) by mx1.freebsd.org (Postfix) with ESMTP id BA25B8FC14 for ; Tue, 5 Jun 2012 17:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; d=embarqmail.com; s=s012408; c=relaxed/simple; q=dns/txt; i=@embarqmail.com; t=1338917556; h=From:Subject:Date:To:Mime-Version:Content-Type; bh=OX+l+IQ023MG1jlt6d9ILJdnzG4=; b=jUPXOHOFVw6iFPZIGu+6RhAx9mRhhNEqQdUjrCSu+ewabN+v0DGDKOKc1g3bX1/6 oUEBwe4qo9NFHcQe4X6CDmyFyCbPb2fDSYANshCNfKyBJH4nYXdxGpb48Itwr5Z7; X_CMAE_Category: 0,0 Undefined,Undefined X-CNFS-Analysis: v=2.0 cv=W/a6pGqk c=1 sm=0 a=jqASBmZdCR7DR2qNErNAVQ==:17 a=LUY_rjA3ehQA:10 a=1poGYrevpj8A:10 a=kj9zAlcOel0A:10 a=1oqGTYSLAAAA:8 a=MnkTnmICAAAA:8 a=EOJYFbmdDo7RUffb0xEA:9 a=CjuIK1q_8ugA:10 a=VAeyC-Qft3gA:10 a=jqASBmZdCR7DR2qNErNAVQ==:117 X-CM-Score: 0 X-Scanned-by: Cloudmark Authority Engine Authentication-Results: smtp04.embarq.synacor.com smtp.user=rpratt1950@embarqmail.com; auth=pass (LOGIN) Received: from [74.4.81.87] ([74.4.81.87:62309] helo=tv.weeeble.com) by mailrelay.embarq.synacor.com (envelope-from ) (ecelerity 2.2.3.47 r(39797/39798)) with ESMTPA id F4/C0-27851-3B24ECF4; Tue, 05 Jun 2012 13:32:36 -0400 Date: Tue, 5 Jun 2012 13:32:34 -0400 From: Randy Pratt To: tundra@tundraware.com Message-Id: <20120605133234.8b9e95e4.bsd-unix@embarqmail.com> In-Reply-To: <4FCE287D.3090501@tundraware.com> References: <4FCE287D.3090501@tundraware.com> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.14.7; i386-portbld-freebsd6.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List Subject: Re: Possible /bin/sh Bug? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jun 2012 17:32:43 -0000 On Tue, 05 Jun 2012 10:40:45 -0500 Tim Daneliuk wrote: > Given this script: > #!/bin/sh > > foo="" > while read line > do > foo="$foo -e" > done > echo $foo > > Say I respond 3 times, I'd expect to see: > > -e -e -e > > Instead, I get: > > -e -e The last line "echo $foo" is what is getting confused. At the end of 3 passes, $foo contains " -e -e -e" so when the last line is executed, it looks like: echo -e -e -e The first -e is probably being interperted by "echo" as a flag ( echo -e ) and then only prints the last two -e. Its easier to see if you execute the script with xtrace: sh -x /path/to/script I'd recommend that you write the last line with quotes: echo "$foo" and I think it'll produce the results you expect. HTH, Randy