Added exec_process_substitution
This commit is contained in:
parent
7b01bcf456
commit
4989ee8d05
27
general_utils
Normal file
27
general_utils
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
source ./log_helpers
|
||||||
|
|
||||||
|
exec_process_substitution () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
log_debug "$func:${LINENO} exec-ing [$*]"
|
||||||
|
|
||||||
|
exec {fd}< <(eval "$@")
|
||||||
|
local ps_pid=$! # remember pid of process substitution
|
||||||
|
|
||||||
|
local __result=""
|
||||||
|
while read __tmp <&$fd; do
|
||||||
|
if ! [ -z "$__tmp" ]; then
|
||||||
|
__result="${__result}$__tmp"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exec {fd}>&- # close fd (i.e. process substitution)
|
||||||
|
wait $ps_pid # wait for the subshell to finish
|
||||||
|
|
||||||
|
__result=${__result//[$'\r\n\t']/ } # remove \r\n\t from __result
|
||||||
|
|
||||||
|
log_debug "$func:${LINENO} result=$__result"
|
||||||
|
printf '%s' $__result
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user