Skip to content
loading...

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

github logo ・1 min read  

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 >

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.

twitter logo DISCUSS
Classic DEV Post from Apr 5

How does deployment work at your organization?

What is the process to get code into prod?

Mich Rodz profile image
Python. DevOps. Tech enthusiast.