diff options
author | Jonas Kohl | 2024-11-06 15:37:39 +0100 |
---|---|---|
committer | Jonas Kohl | 2024-11-06 15:37:39 +0100 |
commit | 557bb0c775f880ac7de99b9608045ff206614ed8 (patch) | |
tree | 20fc0e980cece66d06837d75ec150e3830b09d60 /functions.sh |
Initial commit
Diffstat (limited to 'functions.sh')
-rw-r--r-- | functions.sh | 8 |
1 files changed, 8 insertions, 0 deletions
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) +} |