Project

General

Profile

« Previous | Next » 

Revision 10770

lib/sh/util.sh: filter_fd(): factored out >() subshell command into stdout2fd() for clarity

View differences:

lib/sh/util.sh
640 640
	set_fds "$1"
641 641
}
642 642

  
643
stdout2fd() # usage: fd=# stdout2fd cmd...
644
{
645
	echo_func; kw_params fd; : "${fd?}"
646
	local redirs=(">&$fd" "${redirs[@]}")
647
	redir "$@"
648
}
649

  
643 650
function filter_fd() # usage: (fd=# [redirs=] filter_fd filter_cmd...; \
644 651
# with filter...) # be sure ${redirs[@]} is not set to an outer value
645 652
# useful e.g. to filter logging output or highlight errors
646 653
{
647 654
	echo_func; kw_params fd; : "${fd?}"
648
	set_fds "$fd>" >(pipe_delay; redirs=(">&$fd" "${redirs[@]}"); redir "$@")
655
	set_fds "$fd>" >(pipe_delay; stdout2fd "$@")
649 656
	pipe_delay; pipe_delay # wait for >()'s pipe_delay and initial logging
650 657
}
651 658
alias filter_fd='"filter_fd" ' # last space alias-expands next word

Also available in: Unified diff