reworking content
All checks were successful
learn org at code.softwareshinobi.com/linux.softwareshinobi.com/pipeline/head This commit looks good
All checks were successful
learn org at code.softwareshinobi.com/linux.softwareshinobi.com/pipeline/head This commit looks good
This commit is contained in:
44
landing/docs/Bash-Scripts/0131-debugging.md
Normal file
44
landing/docs/Bash-Scripts/0131-debugging.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Debugging
|
||||
|
||||
Ensure your Bash scripts run flawlessly. Master debugging to identify issues quickly and build robust code.
|
||||
|
||||
### 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
|
||||
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`:
|
||||
|
||||
```bash
|
||||
touch debug_example.sh
|
||||
```
|
||||
|
||||
Open `debug_example.sh` and add:
|
||||
|
||||
```bash
|
||||
#!/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:
|
||||
|
||||
```bash
|
||||
chmod +x debug_example.sh
|
||||
./debug_example.sh
|
||||
```
|
||||
|
||||
Master these debugging techniques. They are indispensable for building high-quality, dependable Bash scripts.
|
||||
Reference in New Issue
Block a user