I want to write to only stderr using /dev/tty . If I write directly to /dev/tty (with tee), it seems like that will print out on stdout. Is that correct? How can I specify that I want to print to stderr?

Currently the line in bash looks like

echo "foo" >&2 | tee /dev/tty | logger -it "my_script"
有帮助吗?

解决方案

If we split apart your command apart with the result of each command after the #

echo "foo" >&2 # echo "foo" and redirect to fd 2 (/dev/sdterr)
| #pipe stdout to  
tee /dev/tty #both send stdout to file /dev/tty, which is terminal file that can output both stdout and stderr depending on what you pass to it (so you probably want /dev/stdout/ or /dev/stderr directly instead) and pass it along to the next pipe
| #pipe stdout to
logger -it "my_script"

So it depends on what you want to do (In the above foo gets redirected to stderr and nothing gets piped to tee)

If you want to print foo to stderr and pass stdout to your script you can just do

echo "foo" | tee /dev/stderr | yourscirpt

Then tee will print to stderr and foo will get piped as stdout to yourscript.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top