I have a would-be POSIX script that includes filtering the stderr output:
exec <cmd> "$@" 2> >(grep -v "blih bluh blah")
Redirection does not occur because process substitution is undefined (viz [SC3001]). I played with file descriptors and looked at this post as well as at others, but I am not sure about the implications of:
exec <cmd> "$@" 2>/dev/fd/5; exec grep -v "blih bluh blah" 5<&- >&2
or perhaps
exec <cmd> "$@" 2>/dev/fd/5 && grep -v "blih bluh blah" 5<&- >&2
Critical eye(s) would be welcome.
EDIT: what I intend should probably be closer to:
exec {<cmd> "$@"; grep -v "blah" /dev/fd/5 5<&- >&2} 5<&2
although I can sense at least 2 issues here, with: (i) grep being executed asynchronously, as it is instructed behind a ";", and (ii) the way redirection of stderr as specified affects the current shell execution environment.
In addition in the above expression exec is followed by a command, so the shell is replaced with <cmd> without creating a new process. The POSIX man pages specifies that if arguments are specified, they are interpreted as arguments to <cmd>. But is that limited to "$@" here ?
And how does exec deal with exec {<cmd1>; <cmd2>} 5<&2 ?