将stdout复制到stderr [英] Duplicating stdout to stderr

查看:63
本文介绍了将stdout复制到stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也希望在bash下将命令的stdout复制到stderr.像这样:

I'd like to have the stdout of a command replicated to stderr as well under bash. Something like:

$ echo "FooBar" (...)
FooBar
FooBar
$

其中(...)是重定向表达式.有可能吗?

where (...) is the redirection expression. Is that possible?

推荐答案

在/dev/stderr中使用tee:

Use tee with /dev/stderr:

echo "FooBar" | tee /dev/stderr

或使用awk/perl/python手动进行复制:

or use awk/perl/python to manually do the replication:

echo "FooBar" | awk '{print;print > "/dev/stderr"}'

echo "FooBar" | perl -pe "print STDERR, $_;"

这篇关于将stdout复制到stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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