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 .
1 Answer
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
6 Comments
Charles Duffy
Certainly not even remotely the closest thing. A single-step-capable debugger exists; upstream bash has hooks explicitly for its use.
Charles Duffy
@iconoclast bashdb.sourceforge.net -- mind, I don't personally use it, so don't take that as a recommendation.
Charles Duffy
@iconoclast, ...btw, re: the "hooks for its use", see the
DEBUG trap, and the extdebug shell option modifying behavior of same.We'll See
I 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
Joshua Clayton
I'll upvote it because set -x plus echo is what OP SHOULD be asking for. :)
|

printfshould be used whenever you might otherwise reach forecho -eorecho -n. See relevant discussion in the APPLICATION USAGE and RATIONALE sections of the POSIX spec forecho, and note that while bash'sechois noncompliant by default, that's subject to runtime configuration (with compile-time defaults) and not thus always true.