开发者

Echo to both stdout and stderr

开发者 https://www.devze.com 2023-03-23 15:54 出处:网络
I have a probably pretty easy beginner question: How do I echo from a shell开发者_StackOverflow script into both stdout and stderr?

I have a probably pretty easy beginner question: How do I echo from a shell开发者_StackOverflow script into both stdout and stderr? I know that I can echo to stderr echo "foo" 1>&2 but I need the output in both. I tried some Googling but nothing worked.


This should do it

 echo "foo" | tee /dev/stderr 


echo foo | tee >(cat >&2)

This will work even if stderr is not supported.

Note: Soren's answer will not work if you have su'ed to another account that does have write permissions to the tty; but mine will.

0

精彩评论

暂无评论...
验证码 换一张
取 消