3 ms·
I have over the years developed a similar template. It’s got usage, arg parsing, etc. One thing I find incredibly useful, which doesn’t appear in the minimal t
by mjgs 6y ago
I have over the years developed a similar template. It’s got usage, arg parsing, etc.
One thing I find incredibly useful, which doesn’t appear in the minimal template presented here (unless I’ve missed it), is the ability to run the program in a mode where it prints out debug info like variables getting set, function names and line numbers.
I add this to the start of every bash script:
if [ -n "$DEBUG" ]; then
echo "$0: Setting bash option -x for debug"
PS4='+($(basename ${BASH_SOURCE}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
fi
Then to run with debug info printed just set DEBUG=1
Ideally there would be a debugger where you could step through code, but this is the closest I’ve found to that.