2

enter image description here

I work with git-bash in windows. I have found a bash script that I would like to modify on GitHub. I cloned it and opened it in my pycharm editor. There is a plugin https://www.plugin-dev.com/project/bashsupport/#installation which I've added, but from the documentation this does things like syntax highlighting. Is there a way to step through the code line by line, set breakpoints etc. I don't have much shell scripting experience and stepping through the code might speed up my learning .

user1592380
  • 30,233
  • 76
  • 247
  • 468
  • You can run one line of your script at a time in the shell... – Mad Physicist Apr 14 '18 at 21:12
  • Googling "bash debugger", I found http://bashdb.sourceforge.net/. I've never heard of it before so can't say anything for or against. – Mad Physicist Apr 14 '18 at 21:15
  • As an aside -- generally speaking, `printf` should be used whenever you might otherwise reach for `echo -e` or `echo -n`. See relevant discussion in the APPLICATION USAGE and RATIONALE sections of [the POSIX spec for `echo`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html), and note that while bash's `echo` is noncompliant *by default*, that's subject to runtime configuration (with compile-time defaults) and not thus always true. – Charles Duffy Apr 14 '18 at 21:21

1 Answers1

2

I usually debug using -x flag (short for xtrace or execution trace) is useful to add execution information Debugging Bash scripts).

You can use it by executing:

bash -x your-script.sh

or adding adding into your script:

set -x
Gonzalo Matheu
  • 7,710
  • 4
  • 32
  • 53