Answers:
因为你使用的sh
,而不是bash
,然后echo
命令在sh
没有选项-e
。从sh
联机帮助页:
echo [-n] args...
Print the arguments on the standard output, separated by spaces.
Unless the -n option is present, a newline is output following the
arguments.
而且它也没有\e
:
If any of the following sequences of characters is encountered
during output, the sequence is not output. Instead, the specified
action is performed:
\b A backspace character is output.
\c Subsequent output is suppressed. This is normally used at
the end of the last argument to suppress the trailing new‐
line that echo would otherwise output.
\f Output a form feed.
\n Output a newline character.
\r Output a carriage return.
\t Output a (horizontal) tab character.
\v Output a vertical tab.
\0digits
Output the character whose value is given by zero to three
octal digits. If there are zero digits, a nul character
is output.
\\ Output a backslash.
All other backslash sequences elicit undefined behaviour.
sh
实现支持echo -e
,在编译时bash
可以告诉不支持echo -e
。这只是特定SH(可能dash
)不支持-e
,而该特定bash
一样。
echo
内置功能/bin/sh
dash
(该操作系统可以将Linux或FreeBSD作为其内核)。