Because apparently Mac OS is one of the systems which responds to the xpg_echo
option when run in POSIX mode. Running bash as /bin/sh is equivalent to running with either --posix
or setting POSIXLY_CORRECT.
The solution is to stop using echo
except in cases where there can be no ambiguity. printf
is the portable replacement. Never use option flags to echo, (and use printf
if you do).
There are multiple incompatible historical implementations of echo
which break its specification in a way that can't be fixed, and the option flags are therefore non-portable. I'm not aware of anything that currently implements POSIX echo
correctly.
shopt -u xpg_echo
should modify this behavior. Also as you've already discovered, not running in POSIX mode.
Also you might want to upgrade... bash 3 is getting a little crusty. Many bugs have been fixed since.