7

I inherited a over 700 line shell script and noticed that when I ran the script it spits out error at some point of execution.

E.g error that I see on the console is something like

cat: /Wreck/wreck_module.rb: No such file or directory 

I have tried to use set -x and most of the tips from this link, however I noticed that all the output that I was getting were pretty noisy.

Is there a way to get the exact line number of where a shell command returned a non-zero status?

Community
  • 1
  • 1
tawheed
  • 5,565
  • 9
  • 36
  • 63

1 Answers1

4

Put this at the top of the script you want to debug:

#!/bin/bash
function trace_line(){
  caller
}
trap trace_line debug

and perhaps redirect the output to a file for easy analysis.

perreal
  • 94,503
  • 21
  • 155
  • 181