How To Debug a Bash Shell Script?

The fastest way to debug a Bash script is to enable debug mode. This prints each command before execution, helping you find problems. 

In this tutorial, we’ll explore various techniques for debugging Bash shell scripts. Although the Bash shell doesn’t have a built-in debugger, we can effectively use certain commands and constructs to aid in this process. First, we’ll understand how to use the set command for script debugging. Next, we’ll discuss specific uses of the set and trap commands. Finally, we’ll outline some strategies for debugging a script that’s already running.

What is Shell?

The UNIX shell program interprets user commands which are either directly entered by the user, or which can be read from a file called the shell script or shell program. Shell scripts are interpreted, not compiled. The shell reads commands from the script line per line and searches for those commands on the system. Continue reading “How To Debug a Bash Shell Script?”