linux - Escape echo output from redirecting to a file -
this question has answer here:
i have script following
function long_proc() { #script1 generate output1 #script2 generate output2 .... } long_proc > /tmp/debug.log
my requirement complete log should divert /tmp/debug.log
output of script2 should go stdout
log file.
can 1 me?
so think want do.
to keep output on stdout go file
long_proc(){ exec 4>&1 #redirect fd4(currently nothing hopefully) stdout exec 1>&3 #redirect stdout fd3(also unused) #note have 5 more choose if in use. echo log #script1 generate output1 echo log , stdout | tee >(cat - >&4) #script1 generate output2 # tee subproc cat data fd4 pointing stdout #the tee'd data goes fd3 exec 1>&4 # set fd1 stdout exec 4>&- #close fd4 } long_proc 3> log #send fd3 log, stdout untouched , whatever want.
so redirect output fd3, piped log. tee stdout want in stdout.
benefit of can pipe like
long_proc 3> log | sed 's/^/piped , /'
Comments
Post a Comment