# Debugging Scripts: bash -x

bash -x runs a script and prints every line before it runs, with its variables already filled in, so you can watch what the script really did; set -x and set +x trace one part only, and PS4 adds line numbers to the trace.

![Cheat sheet for the lesson Debugging Scripts: bash -x: bash -x runs a script and prints every line before it runs, with its variables already filled in, so you can watch what the script really did; set -x and set +x trace one part only, and PS4 adds line numbers to the trace.](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/9daf838f326d4d43a88d9040dc84ea52.webp)

- Category: Bash
- Level: Journeyman
- Tags: execution-trace, linux, ps4, shell-script, standard-streams, unix
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/bash-debugging-scripts-cheat-sheet
