So i've got tool to debug shell scripts:
#!/bin/sh
# this tool allows to get full xtrace of any shell script execution
# only argument is script name
out=out.$1
err=err.$1
tmp=tmp.$1
echo "export SHELLOPTS; sh $@ 1>> $out 2>> $err" > $tmp
sh -eux $tmp &> /dev/null
rm $tmp