便于调试bash的输出效果:
#!/usr/bin/env bash
if [ -z "$1" ];then
echo "usage: bashdebug your_script"
exit 1
fi
PS4='+[$(date "+%Y-%m-%d %H:%M:%S") +${SECONDS}s ${BASH_SOURCE} ${LINENO}] ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
ACK=""
which ack &>/dev/null
[ $? -eq 0 ] && ACK=$(which ack)
if [ -z "$ACK" ];then
bash -x $1
else
bash -x $1 |& $ACK --passthru "^\+.*:"
fi