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 .
Asked
Active
Viewed 3,834 times
5
-
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 Answers
3
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
- 8,984
- 5
- 35
- 58
-
Certainly not even remotely the closest thing. A single-step-capable debugger exists; upstream bash has hooks explicitly for its use. – Charles Duffy Apr 14 '18 at 21:18
-
-
1@iconoclast http://bashdb.sourceforge.net/ -- mind, I don't personally use it, so don't take that as a recommendation. – Charles Duffy Jan 01 '22 at 03:04
-
1@iconoclast, ...btw, re: the "hooks for its use", see the `DEBUG` trap, and the `extdebug` shell option modifying behavior of same. – Charles Duffy Jan 01 '22 at 03:05
-
1I didn't know this, so thank you! Not upvoting your answer though because I don't think it is really what the OP is looking for – We'll See Dec 01 '22 at 12:02