To complement @that other guy's helpful answer:
Even when it is bash
executing your script, there are several ways in which the observed behavior - echo
by default interpreting escape sequences such as \n
- can come about:
shopt -s xpg_echo
could be in effect, which makes theecho
builtin interpret\
escape sequences by default.enable -n echo
could be in effect, which disables theecho
builtin and runs the external executable by default - and that executable's behavior is platform-dependent.
These options are normally NOT inherited when you run a script, but there are still ways in which they could take effect:
- If your interactive initialization files (e.g.,
~/.bashrc
) contain commands such as the above and yousource
(.
) your script from an interactive shell. - When not sourcing your script: If your environment contains a
BASH_ENV
variable that points to a script, that script is sourced before your script runs; thus, if that script contains commands such as the above, they will affect your script.