tag 21919 notabug close 21919 stop On 15/11/15 23:59, Pádraig Brady wrote: > On 14/11/15 16:00, Tim Shaw wrote: >> If I am using stdout redirection of a shell block to capture some text I am >> generating, errors need to go to stderr, but it would also be good if they >> went into the generated output. For example >> for i in files*; do >> if there_is_an_error; then >> echo big long complicated error message goes here >&2 >> echo big long complicated error message goes here >> continue >> fi >> stuff_producing_text_on_stdout >> done > file_i_am_creating >> >> I do not like duplicating code, such as the big long error message echo. So, >> I could create a temp file or a temp shell var to save the message, but that >> makes things more complicated than just duplicating the code, and also is >> just not my style for something transient like this. >> >> What I would like to do is add a parameter to tee, "-2", that copies to >> stderr in addition to stdout, just like "-" copies to stdout twice. > > Note `tee -` now copies to a file called '-' rather than > duplicating to stdout, since v8.24 as discussed at: > http://lists.gnu.org/archive/html/coreutils/2015-02/msg00085.html > >> So the code becomes >> echo big long complicated error message goes here | tee -2 >> Simple, eh? >> >> Where's the tee source?
tee source is at http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/tee.c > I know this would not be POSIX compliant, but it would work for me, and I > hate having to rewrite everything from scratch for trivial stuff like this. > > Maybe shell constructs like this would suffice? > > { echo error | tee >(cat >&2); } Or this is simpler: echo error | tee /dev/stderr cheers, Pádraig.
