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