From owner-freebsd-questions@FreeBSD.ORG Tue Jun 5 17:37:42 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 87D6F106566B for ; Tue, 5 Jun 2012 17:37:42 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 2985D8FC08 for ; Tue, 5 Jun 2012 17:37:41 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id q55Hbx54013730; Tue, 5 Jun 2012 12:37:59 -0500 (CDT) Date: Tue, 5 Jun 2012 12:37:59 -0500 (CDT) From: Robert Bonomi Message-Id: <201206051737.q55Hbx54013730@mail.r-bonomi.com> To: tundra@tundraware.com In-Reply-To: <4FCE287D.3090501@tundraware.com> Cc: freebsd-questions@freebsd.org 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:37:42 -0000 > From: Tim Daneliuk > > 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 > > Linux appears to do the right thing here, so this seems like it > is a bug ... or am I missing something? Yup. there are -multiple-, incompatible, standards for 'echo'. a SYS-V derived echo will behve diferently than UCB based one. varous shell-program 'built-in' implementtions may have yet different behavior. Recommendation -- use 'print' instead of 'echo', it is much more predictble in differnt environments. ALTERNATIVE: replace the last line of the script with: echo -- $foo