管道无法与echo命令一起使用 [英] Piping not working with echo command

查看:232
本文介绍了管道无法与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

为什么pipingecho输出到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆