Debugging Linux Bash Scripts

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/debugging-linux-bash-scripts/
PINTEREST
PINTEREST
INSTAGRAM
  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging

While writing bash scripts we generally expects some results and provide these results to other scripts. But things goes not well as we expect. So we need to see under the hood and what is happening while script is running. Debugging is inspecting bash scripts to see what is wrong with script or show detailed information about script run.

Debugging Whole Script

To make whole script debug mode use -x parameter when calling the script

Our script is simple just issue host name -I command. As we can see that issued command is echoed to the console with +sign.

Debugging Some Part of Script

Debugging is useful even we have no problem with the script. It can give information about execution of the script. For long and big script files it may become hard to look debug. Some part of the bash script can be made debug-able like below.

This is our script where we set on debug with set -x and then set off with set +x.

LEARN MORE  Linux Bash How to Define, Use Shell Variables

After activating debug we can see the script command but after disabling debugging we can only see script output and cannot see script commands.

  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/debugging-linux-bash-scripts/
PINTEREST
PINTEREST
INSTAGRAM

One Reply to “Debugging Linux Bash Scripts”

  1. It’s a brilliant tutorial. Easy to understand and it’s Newbie-Friendly. I read this tutorial for a whole night and practiced for BASH again and again. I feel I can really do some jobs with BASH now. Thanks for ─░smail Baydan, very nice tutorial.

Leave a Reply

Your email address will not be published.