echo 和 cat - 抑制新行字符
下面是示例。我可以看到,当我将 echo 与 cat 一起使用时,它会抑制新行字符。这是预期的行为吗?我正在Solaris unix 上工作。
.262> cat temp2.txt
20110801
20110802
20110803
20110804
20110805
20110808
> echo `cat temp2.txt `
20110801 20110802 20110803 20110804 20110805 20110808
Below is the example.I can see that when i use echo with cat it suppresses the new line characters.Is this the expected behaviour?I am working on solaris unix.
.262> cat temp2.txt
20110801
20110802
20110803
20110804
20110805
20110808
> echo `cat temp2.txt `
20110801 20110802 20110803 20110804 20110805 20110808
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是预期的行为。
但正如“Mark Reed”建议的那样,您可以通过使用引号来保留空格:
Yes this is the expected behaviour.
But as "Mark Reed" suggested you can keep the white space by using quotes:
是的,这是预期的行为。
我不知道有哪个 shell 不这样做。
它记录在 bash 中:
在 zsh 中:(
编辑:我删除了命令行的输出,因为它们毫无意义,正如 @sehe 在评论中指出的那样)
Yes this is expected behavior.
I don't know of any shell that doesn't do it.
It is documented in bash:
In zsh:
(Edit: I removed the output of the command lines as they are pointless, as pointed out by @sehe in the comment)