(Linux bash 4.1.2) I have a bash function calling another function. The low level function wants to have -xv set for debugging, but I don't want it to mess with the values of x and v in the parent function. I.e. I want the child function to push -xv, then restore the previous setting on return. E.g.:
function outer(){ echo starting; inner; echo done; }
function inner(){
set -xv
echo inside
set +xv
}
outer
This works if the setting in outer is default; otherwise it forces +xv in the rest of outer's code. I can imagine some very messy script that parses BASHOPTS, but it seems like there should be a better way?