summaryrefslogtreecommitdiffstats
path: root/skripti/sponge_only_on_success.sh
blob: 8b3ed309daf22979265cdd25c988ff42e635cf20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
p=`rev <<<$0 | cut -d/ -f1 | rev`
t=`mktemp -p "" $p.XXX`
trap "rm $t" EXIT
o=$1
shift
$@ > $t
r=$?
if [ $r -eq 0 ]
then
cat $t > $o
else
echo called command $@ exited with nonzero $r >&2
exit $r
fi