2

I have a very high level and complicated script which I basically need to debug with set -e on (because I'd like it not to run expensive operations in a loop as I work out the logic), but it is becoming difficult (even with set -x) to figure out exactly where the scripts are exiting due to an unexpected result.

I have about 3 scripts calling each other in various ways (combined with inotifywatch) so you can see how this gets a bit hairy.

I'm looking for something like "Script x.sh exited at line 4" rather than the uninformative [exited]

Steven Lu
  • 36,733
  • 50
  • 179
  • 328

1 Answers1

1

Read man bash about trap, BASH_LINENO and FUNCNAME.

You should be able to use trap to call an own function in case of an error. In this function you can use the given arrays to get an idea what went wrong.

michas
  • 22,506
  • 9
  • 64
  • 105
  • 1
    Oh! awesome! Wow, I am **already** using an exit trap in one of these scripts. Never thought to take advantage of it further. – Steven Lu May 22 '13 at 00:32