6

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 .

3
  • You can run one line of your script at a time in the shell... Commented Apr 14, 2018 at 21:12
  • Googling "bash debugger", I found bashdb.sourceforge.net. I've never heard of it before so can't say anything for or against. Commented Apr 14, 2018 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, 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. Commented Apr 14, 2018 at 21:21

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

6 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.