in Bash you can set -x to enable debugging, is there any way to know if that has been set or not from within the script?
Use the following:
if [[ "$-" == *x* ]]; then
echo "is set"
else
echo "is not set"
fi
From 3.2.5. Special parameters:
A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i).
$ [ -o xtrace ] ; echo $?
1
$ set -x
++ ...
$ [ -o xtrace ] ; echo $?
+ '[' -o xtrace ']'
+ echo 0
0