Files
linux.softwareshinobi.com/landing/docs/Bash-Scripts/013-debugging.md
Software Shinobi 7d9171c854
All checks were successful
learn org at code.softwareshinobi.com/linux.softwareshinobi.com/pipeline/head This commit looks good
reworking content
2025-06-19 10:03:08 -04:00

835 B

Debugging

Debugging is vital for efficient Bash scripting.

Debugging Your Scripts

Troubleshoot your Bash scripts by tracing execution. Use -x directly or set -x for specific sections.

Run your script with bash -x to see every command executed:

bash -x ./your_script.sh

For targeted debugging, use set -x where you want to start tracing, and set +x to stop.

Create debug_example.sh:

touch debug_example.sh

Open debug_example.sh and add:

#!/usr/bin/env bash

echo "Starting script."
set -x # Enable debug mode from here
ls -l
my_variable="test_data"
echo "Variable is: $my_variable"
set +x # Disable debug mode
echo "Debugging finished."

Save, make executable, and run:

chmod +x debug_example.sh
./debug_example.sh