0

It is easy to redirect stdout or stderr to the same output (file or one of the 2 std output) with a 1>&1,>&2 and/or >file but is there a way to send the same output to both the std output in KSH (like | tee File but with &2 as file) ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43

2 Answers2

1
#!/bin/ksh

function mytee { 
        while read -r x ; do
                print "${x}"
                print "${x}" >&2
        done
}

echo "TestMyTee
second line
and a * character" | mytee

# Really stdout and stderr?
echo "TestMyTee
second line
and a * character" | mytee 1>mystdout 2>mystderr

Edited: replaced [read] and [echo] by [read -r] and [print]

Walter A
  • 19,067
  • 2
  • 23
  • 43
  • ok, quite simple batch, good idea. Just adapt the read to allow `\\` with a -r and maybe use a printf instead of echo to avoid interpretation by shell – NeronLeVelu Nov 28 '14 at 10:29
0

Response on Unix & Linux

Post: How can I redirect the same message to both stdoud and stderr (without temporary object)

by Stéphane Chazelas

{ your-code } | perl -pe 'print STDERR'
Community
  • 1
  • 1
NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43