回声" -e"不打印任何东西 [英] echo "-e" doesn't print anything
问题描述
我使用GNU的bash,版本3.00.15(1)-release下(x86_64-红帽Linux的GNU的)。而这个命令:
I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:
echo "-e"
不打印任何东西。我想这是因为-e是echo命令,因为回声-n的一个有效的选项之一,回声-E(其他两个选项)也会产生空字符串。
doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty strings.
问题是如何逃脱的顺序-e回声,以获得自然输出(-e)。
The question is how to escape the sequence "-e" for echo to get the natural output ("-e").
推荐答案
这是一个艰难的一个;)
This is a tough one ;)
通常你会使用双破折号告诉命令,它应该停止间preting选项,但回响只会输出的:
Usually you would use double dashes to tell the command that it should stop interpreting options, but echo will only output those:
$ echo -- -e
-- -e
您可以使用-e自身来解决这个问题:
You can use -e itself to get around the problem:
$ echo -e '\055e'
-e
此外,正如其他人所指出的,如果你不使用内置的回声
,您 /斌/回声二进制可能是GNU版本的工具(请查阅手册页),从而了解
POSIXLY_CORRECT
环境变量:
Also, as others have pointed out, if you don't insist on using the bash builtin echo
, your /bin/echo
binary might be the GNU version of the tool (check the man page) and thus understand the POSIXLY_CORRECT
environment variable:
$ POSIXLY_CORRECT=1 /bin/echo -e
-e
这篇关于回声" -e"不打印任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!