1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-22 02:19:06 +01:00
limosek-zaf/lib/zafret

53 lines
769 B
Plaintext
Raw Normal View History

2016-12-09 12:40:25 +01:00
#!/bin/sh
. $(dirname $0)/preload.sh
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
zaf_err "zafret valuefile stderrfile retcode [return return_if_null return_if_error]"
exit 1
fi
value="$(cat $1)"
rm -f $1
shift
stderr="$(cat $1)"
rm -f $1
shift
retcode="$1"
shift
if [ -n "$1" ]; then
ret="$1"
shift
fi
if [ -n "$1" ]; then
retnull="$1"
shift
fi
if [ -n "$1" ]; then
reterr="$1"
shift
fi
if [ "$retcode" != 0 ]; then
echo "$reterr"
zaf_wrn "${ITEM_KEY}("$*"): Error code '$retcode', returning '$reterr' ($stderr)"
exit $retcode
fi
if [ -z "$value" ]; then
echo "$retnull"
zaf_wrn "${ITEM_KEY}("$*"): Got empty result, returning '$retnull' ($stderr)"
exit
fi
echo $value
if [ -n "$stderr" ]; then
zaf_wrn "${ITEM_KEY}("$*"): $stderr"
fi