The default is to expand escape sequences, the -e option is non-standard.
If your echo implementation does not include -e in the echo output, it is non-compliant.
The problem here is that there are implementations that only follow the minimal POSIX requirements and ignore the fact that a platform that is allowed to be called UNIX
-compatible needs to implement support for the POSIX XSI
enhancements.
BTW: bash on MacOS X and Solaris is compiled to always expand escape sequences. Bash in the default compile variant is not POSIX XSI compliant.
POSIX compliant shells like ksh93, bosh or dash expand escape sequences by default as required.
If you like to check the behavior, your test string is not a good idea. A better test would be:
echo '\tfoo'
and to check whether foo
is prepended by a tab character in the output.
The reason, why you may had problems is that you used foo\\bar
and that the shell treats backslashes in double quoted strings already. If you like to check the echo
behavior, you need to use single quoted strings as arguments.
bash
shell, then I can not reproduce what you are seeing. Are you sure that you used double quotes in both examples? Note that the shell will also interpret the backslash as a quoting characters in front of some characters in a double quoted string (backslash being one of these characters, see here). Make sure that you understand this standard behavior before trying to understand the non-standard-e
option toecho
. – Kusalananda Mar 15 '20 at 23:19