Date: Tue, 5 Jun 2012 12:37:59 -0500 (CDT) From: Robert Bonomi <bonomi@mail.r-bonomi.com> To: tundra@tundraware.com Cc: freebsd-questions@freebsd.org Subject: Re: Possible /bin/sh Bug? Message-ID: <201206051737.q55Hbx54013730@mail.r-bonomi.com> In-Reply-To: <4FCE287D.3090501@tundraware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> From: Tim Daneliuk <tundra@tundraware.com> > > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206051737.q55Hbx54013730>