I was wondering if there is a way to pipe the output of a command and direct it to the stdout. So for example, fortune
prints a fortune cookie and also copies it to the clipboard:
$ fortune | tee >(?stdout?) | pbcopy
"...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and
the Ugly)."
(By Matt Welsh)
Best Answer
Your assumption:
won't work because the
fortune
output will be written to standard out twice, so you will double the output topbcopy
.In OSX (and other systems support
/dev/std{out,err,in}
), you can check it:output
2
twice instead of1
and2
.tee
outputs twice tostdout
, andtee
process'sstdout
is redirected tosed
by the pipe, so all these outputs run throughsed
and you see double2
here.You must use other file descriptors, example standard error through
/dev/stderr
:or use
tty
to get the connected pseudo terminal:With
zsh
andmultios
option set, you don't needtee
at all: