管道无法与echo命令一起使用 [英] Piping not working with echo command
本文介绍了管道无法与echo命令一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行以下Bash
脚本时,我希望它可以打印Hello
.而是打印空白行并退出.
When I run the following Bash
script, I would expect it to print Hello
. Instead, it prints a blank line and exits.
echo 'Hello' | echo
为什么piping
从echo
输出到echo
无效?
推荐答案
echo
打印所有参数.它不会从stdin
读取.因此,第二个echo
打印所有参数(无)并退出,而忽略stdin
上的Hello
.
echo
prints all of its arguments. It does not read from stdin
. So the second echo
prints all of its arguments (none) and exits, ignoring the Hello
on stdin
.
对于读取其stdin
并将其打印到stdout
的程序,请使用cat
:
For a program that reads its stdin
and prints that to stdout
, use cat
:
$ echo Hello | cat
Hello
这篇关于管道无法与echo命令一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文