From 557bb0c775f880ac7de99b9608045ff206614ed8 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Wed, 6 Nov 2024 15:37:39 +0100 Subject: Initial commit --- functions.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 functions.sh (limited to 'functions.sh') diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..84a924b --- /dev/null +++ b/functions.sh @@ -0,0 +1,8 @@ +#catch STDOUT_VARIABLE STDERR_VARIABLE COMMAND [ARG1[ ARG2[ ...[ ARGN]]]] +catch() { + { + IFS=$'\n' read -r -d '' "${1}"; + IFS=$'\n' read -r -d '' "${2}"; + (IFS=$'\n' read -r -d '' _ERRNO_; return ${_ERRNO_}); + } < <((printf '\0%s\0%d\0' "$(((({ shift 2; "${@}"; echo "${?}" 1>&3-; } | tr -d '\0' 1>&4-) 4>&2- 2>&1- | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1) +} -- cgit v1.2.3