关于使用echo -n命令的终端手册页面如下:
-n Do not print the trailing newline character. This may also be
achieved by appending `\c' to the end of the string, as is done by
iBCS2 compatible systems. Note that this option as well as the
effect of `\c' are implementation-defined in IEEE Std 1003.1-2001
(``POSIX.1'') as amended by Cor. 1-2002. Applications aiming for
maximum portability are strongly encouraged to use printf(1) to
suppress the newline character.
Some shells may provide a builtin echo command which is similar or iden-
tical to this utility. Most notably, the builtin echo in sh(1) does not
accept the -n option. Consult the builtin(1) manual page.
当我尝试生成MD5哈希时:
echo "password" | md5
它返回286755fad04869ca523320acce0dc6a4
当我执行:
echo -n "password"
它返回在线MD5生成器返回的值:5f4dcc3b5aa765d61d8327deb882cf99
选项-n有何区别?我不理解终端中的条目。
echo
的POSIX规范在http://pubs.opengroup.org/onlinepubs/009604599/utilities/echo.html也是值得的。值得注意的是,它指出`echo -n在所有UNIX系统上都**不可移植**(尽管这比
echo -e`更好,后者无法实现而不违反标准!) - Charles Duffy