Last Updated:

Debug your bash script line by line

Everyone who writes bash scripts knows the problem, that debugging can be a hard task. To make it a lot easier, add the following lines to your script at the top:

#!/bin/bash

set -x
trap "read -u1" DEBUG

The first line tells bash to show every line and what has been executed, the second line will inject a read -u1 after every script command so that you have time to inspect what happened directly before.

Press ENTER subsequently to step through the whole script.

Comments