[英]`echo -n` prints nothing
I used this question to strip the newline from a string, but I've encountered a problem on one host. 我使用此问题从字符串中删除换行符,但在一台主机上遇到了问题。
For some reason, /bin/echo -n foo
prints nothing on that host. 由于某些原因,
/bin/echo -n foo
在该主机上不打印任何内容。 I have no idea why that host behaves oddly. 我不知道为什么那个主持人表现得奇怪。
/bin/echo foo
works fine. /bin/echo foo
工作正常。 It's not the terminal, since echo -n foo > /tmp/bar
also shows nothing. 它不是终端,因为
echo -n foo > /tmp/bar
也什么也不显示。
/bin/echo --help
says that is should work: /bin/echo --help
表示应该可以使用:
Usage: /bin/echo [OPTION]... [STRING]...
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
% /bin/echo --version
echo (GNU coreutils) 5.97
What can possibly cause this not to work? 有什么可能导致此功能不起作用? Could there be some strange buffering in this bash-shell?
这个bash外壳中可能会有一些奇怪的缓冲吗?
Based on information in comments, it appears that /bin/echo -n foo
is producing the expected output, but it's being overwritten by your next shell prompt. 根据注释中的信息,似乎
/bin/echo -n foo
正在产生预期的输出,但是它会被您的下一个shell提示覆盖。 (Most likely it's your shell, not your terminal settings.) (很可能是您的外壳,而不是您的终端设置。)
You can demonstrate this by running 您可以通过运行来演示
/bin/echo -n foo | wc
which should produce this output: 应该产生以下输出:
0 1 3
You can also try this: 您也可以尝试以下操作:
/bin/echo -n foo ; sleep 5
This will delay your next shell prompt for 5 seconds, so you can see the output before it's overwritten. 这会将您的下一个shell提示延迟5秒钟,因此您可以在覆盖之前看到输出。
(What shell are you using? What's the value of $PS1
?) (您使用的是什么shell?
$PS1
的值是多少?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.