0

Is there a way to show which specific line number of a "script.sh" file that is running in terminal after you've entered the "./script.sh" command? Ideally a feature I can turn off and on, that when turned on, shows which line number that terminal is currently processing/reading from, from the bash script.

I feel it would assist me in learning where I'm going wrong in specific bash lines without putting in a makeshift "identifier" i.e. "AAAA" in a bash command line to help me identify where in the script I've made an error.

Are there any addons that can achieve this, or other simple addons that are good to help beginners interpret/fault find scripts they've written (or.. trying to write)?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Naptime
  • 3
  • 1
  • 1
    Does this answer your question? [Unix.SE: How to debug a bash script?](https://unix.stackexchange.com/questions/155551/how-to-debug-a-bash-script) – John Kugelman May 25 '21 at 01:31
  • 1
    Does this answer your question? [How to debug a bash script?](https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script) – John Kugelman May 25 '21 at 01:32
  • 1
    Spend a bit of time with the [Advanced Bash-Scripting Guide](http://tldp.org/LDP/abs/html/). It worth bookmarking the guides [Bash Guide](http://mywiki.wooledge.org/BashGuide), [Bash FAQ](http://mywiki.wooledge.org/BashFAQ), and [Bash Pitfalls](http://mywiki.wooledge.org/BashPitfalls) (especially the Pitfalls `:)` along with [shellcheck.net](https://www.shellcheck.net/) – David C. Rankin May 25 '21 at 01:35
  • Thanks guys, I'll have a read. The problem I've been finding when reading other forum responses is they're typically assuming a base level of knowledge, which is higher than mine, so I end up spending half an hour interpreting their answers, to find out that's not what I was looking for after all. I'll get there eventually, thanks for the replies. – Naptime May 25 '21 at 01:44
  • 2
    The "Advanced Bash Scripting Guide" -- isn't really that "Advanced" -- it would be better as just "Bash Scripting Guide"... The `wooledge.org` site are at a more "reference" or "Advanced" level. [shellcheck.net](https://www.shellcheck.net/) is good for everything from your first `"Hello Bash"` script to the most complex script you can comprehend. Just paste it in ShellCheck and it will point out any problems no matter how basic or advanced. – David C. Rankin May 25 '21 at 02:45
  • 1
    The ABS is problematic for many reasons. It's like the w3schools for Bash - undeservedly popular, and easily shadowed by other resources which are not hard to find. – tripleee May 25 '21 at 04:28
  • @JB : AFIK, there is no way to have the line numbers displayed automatically. I admit that this would be a helpful addition in the case of debugging really huge scripts. In small scripts, it is usually sufficient to see the statement being executed; the line number is not so crucial in finding the spot of interest. – user1934428 May 25 '21 at 07:33
  • @JB : You can, if this helps you, of course manual print the line number. Just prepend each statement of interest with a `echo $LINENO;`. – user1934428 May 25 '21 at 07:35

0 Answers0