Revision 9717
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
535 | 535 |
set_fds "$1" |
536 | 536 |
} |
537 | 537 |
|
538 |
filter_fd() # usage: (fd=# filter_fd filter_cmd...; with filter...) |
|
539 |
# useful e.g. to filter logging output or highlight errors |
|
540 |
{ |
|
541 |
echo_func; kw_params fd; : "${fd?}" |
|
542 |
set_fds "$fd>" >(pipe_delay; redirs=(">&$fd" "${redirs[@]}"); redir "$@") |
|
543 |
pipe_delay; pipe_delay # wait for >()'s pipe_delay and initial logging |
|
544 |
} |
|
545 |
|
|
538 | 546 |
# convention: use fd 40/41/42 for command-specific alternate stdin/stdout/stderr |
539 | 547 |
# do NOT use 1x, which are used by eval (which is used by set_fds()) |
540 | 548 |
# do NOT use 2x, which are used as global stdin/stdout/stderr |
Also available in: Unified diff
lib/sh/util.sh: added filter_fd(), which encapsulates the use of >() process substitution for filtering an fd other than stdout (yes, this is possible without lots of 3>&1 1>&2 2>&3 redirections!). this can be useful e.g. to filter logging output or highlight errors.