Introduction
Use set -x to see each command as it runs. It helps you understand what your script is doing step-by-step.
You want to find out why your script is not working as expected.
You want to learn how a script runs by watching each command.
You need to debug a script that has many commands.
You want to check the values of variables as the script runs.