DEV Community

Cover image for Running (debugging) a bash script line-by-line
An Rodriguez
An Rodriguez

Posted on • Originally published at Medium

Running (debugging) a bash script line-by-line

The other day I was running a Bash script. It wasn't working as expected so it needed some debugging.

I needed a quick-and-dirty solution.

After some googling, I found this answer. It ended up being quite easy and handy.

All you have to do is place this line on the top of your script and Bash will prompt you after executing every line. Hitting enter key is enough to execute the next line of your script.

#!/usr/bin/env bash
set -x
trap read debug

< YOUR CODE HERE >
Enter fullscreen mode Exit fullscreen mode

It is reported that this works "with bash v4.2.8 and v3.2.25."

For me, it worked like a charm.

Here is the original answer in stackoverflow.


Do you have other tips for debugging Bash? I'd like to know.

Top comments (0)