I'm running a bash script which contains a for loop which will run thousands of times. Somewhere in this for loop the code often gets stuck (lowest number of iterations I have seen it stop on is 32, most it has stopped on is in the high 4000s - it is supposed to run 5000 times, sometimes it completes the task). I would like to debug this problem. Obviously, I don't want to manually enters hundreds of thousands of lines of code into the command window and wait for the one where it will get stuck.
Is there a simple way to find out what the last line it executed or tried to execute was? (Bearing in mind that when it goes wrong the terminal appears to be frozen - sometimes the entire system stops working and requires an off-at-the-wall reset to get it started again.) I thought this might be a feature of echo. I found this question and answer but I am not sure what "when commands represent a specific line in my script from a parser standpoint" means and therefore if it is applicable. I'm also pretty confused by what this code actually does and would appreciate for dummies explanation if this code will help me.
Is this the answer I am looking for? Is there another solution to this problem?
echo
command will benefit you in any way inside the for-loop.