【发布时间】:2014-04-24 16:46:37
【问题描述】:
我使用this question 去除字符串中的换行符,但我在一台主机上遇到了问题。
出于某种原因,/bin/echo -n foo 在该主机上不打印任何内容。我不知道为什么那个主机表现得很奇怪。 /bin/echo foo 工作正常。这不是终端,因为echo -n foo > /tmp/bar 也没有显示任何内容。
/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
什么可能导致这不起作用?这个 bash-shell 中会不会有一些奇怪的缓冲?
【问题讨论】:
-
你也可以使用
printf。 -
是的。我让它与
tr -d '\n'一起工作。但我想知道该主机上的echo有什么问题。 -
谁知道?顺便说一句,
echo也是一个内置的 bash。不确定您使用的是哪一个。 -
你确定它什么都不打印吗?也许输出正在被您的 shell 提示符覆盖。试试
/bin/echo -n foo | wc。 (我知道你说过echo -n foo > /tmp/bar什么都没有显示;你是否通过运行cat /tmp/bar来检查?) -
@keith-thompson:是的,我尝试了
cat,但我没有尝试wc。好主意!问题是终端,而不是echo。很奇怪。可能是我的LS_COLORS或INPUTRC。