Debug shell scripts with line numbers

I inherited more than 700 lines of the shell script and noticed that when the script starts, it throws an error at some point in execution.

For example, the error that I see on the console is similar to

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

I tried using set -x and most of the tips from this link , however I noticed that all the output I was getting was quite noisy.

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

+6
source share
1 answer

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

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

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

+4
source

Source: https://habr.com/ru/post/948826/


All Articles