Possible /bin/sh Bug?

Robert Bonomi bonomi at mail.r-bonomi.com
Tue Jun 5 17:37:42 UTC 2012

> From: Tim Daneliuk <tundra at 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

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

More information about the freebsd-questions mailing list