@zwol Sorry, as far as I can tell you don't get anonymous pipes without process substitution, and that's a bashism.

@clacke @zwol I guess my solution is bash specific, alas :

exec 3>(tee -a outfile)

@zwol @brainwane Ooo, that's a good one. In rc you'd do:

sh |[5] tee -a logfile <[5=0]

...and then your resulting sh would have fd 5 held open so you can 'echo foo >&5' and the tee would see it, but I can't come up with a way to convince sh (or friends) that 5 is a valid file descriptor. It seems like you ought to be able to do something with a subshell in that pipeline, but I can't quite get it.

@kn Not in POSIX with either the bash or the ksh syntax :-(

The closest approximation I can think of is to pipe the command to a brace block which wraps the rest of the current script, ala

exec 4<&0
command | {
... everything else...
} 3<&0 0<&4 4<&-

and while 'command' isn't in the foreground in the sense that it doesn't block the rest of the script, it's not background in the sense of pid in $!. That may be sufficient approximation depending on what you're trying to do.

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!