UpdateController/general_utils

50 lines
994 B
Plaintext
Raw Normal View History

2022-06-04 14:35:12 +02:00
#!/bin/bash
# set -x
source ./log_helpers
exec_process_substitution () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"
exec {fd}< <(eval "$@")
2022-06-04 18:10:55 +02:00
local __result_code=$?
2022-06-04 14:35:12 +02:00
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"
2022-06-04 18:10:55 +02:00
return $__result_code
2022-06-04 14:35:12 +02:00
}
usage () {
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
# UpdateController.conf"
}
usage_and_exit () {
usage
exit $1
}
version () {
echo "$PROGRAM version $VERSION"
}
error () {
echo "$@" 1>&2
usage_and_exit 1
}