我无法告诉您为什么它不支持该参数(您可能不得不询问程序员)。我只知道在我的linux机器上,我得到了:
$ /bin/echo --help
Usage: /bin/echo [SHORT-OPTION]... [STRING]...
or: /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version output version information and exit
If -e is in effect, the following sequences are recognized:
*emphasized text*
\0NNN the character whose ASCII code is NNN (octal)
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
NOTE: your shell may have its own version of echo, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
Report echo bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report echo translation bugs to <http://translationproject.org/team/>
- 这没有提到
\e
逃脱
- 它说它
/bin/echo
来自gnu coreutils。随着苹果不时更改其Unix系统组件的来源(例如,从zsh变为bash),请检查/bin/echo
Leopard和Snow Leopard之间是否存在更改。如果是gnu,您可以在gnu.org上询问人们为什么选择不包含这些序列。
至于解决方法(更有趣):不使用/bin/echo
,但是bash的内置功能echo
可在Linux机器上使用。如果他们更改为没有内置回声(甚至更晦涩的东西)的bash,则还可以尝试使用此shell尚不为人所知的功能(至少在bash和zsh中有效):
$ echo $'\e[34m''COLORS'
这是bash的联机帮助页的匹配部分:
Words of the form $'string' are treated specially. The word expands to string, with
backslash-escaped characters replaced as specified by the ANSI C standard. Backslash
escape sequences, if present, are decoded as follows:
\a alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\nnn the eight-bit character whose value is the octal value nnn (one to three
digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or
two hex digits)
\cx a control-x character
The expanded result is single-quoted, as if the dollar sign had not been present.
A double-quoted string preceded by a dollar sign ($) will cause the string to be trans‐
lated according to the current locale. If the current locale is C or POSIX, the dollar
sign is ignored. If the string is translated and replaced, the replacement is double-
quoted.