
Now the TEST_VAR is echoed to the screen. Again, nothing is displayed in the output for this action. The next line turns onto bugging with a set -x command. You'll see in the output that nothing is listed for this command because debugging isn't on at this point. This shows how you can turn debugging on for just a portion of your script. There is no plus sign in front of it because it is output as result of a command and not a command itself. In the output, the result of the echo command, which is test is displayed. The second command is to echo that value to the screen. The first is setting the value of the TEST_VAR variable. In this example, there are two commands that are executed. Those are the commands that are being executed from the script. You'll notice that there are lines that start with a plus sign. At the bottom of the screen is the output you'll see when you run this script. You can see that -x has been added to the end of the shebang. Here's a very simple example that demonstrates the use of the -x option. Again, set, space, -x will start the x-trace while set, space +x will stop the x-trace. Place set +x on a line after the section of the shell script that you're debugging. Just before you want to start displaying the commands to the screen, add a set -x line. You can also use this option for just a portion of your script. Use set, space +x to stop this debugging behavior. If you want to do this at the command line, run set, space, -x. If you're using this option in a shell script simply add -x to the end of the shebang line. You'll sometimes hear this type of debugging called print debugging, tracing or an x-trace. Wild cards aren't displayed but what they expand to is displayed. This means that instead of variables being displayed, the values of those variables are displayed. The -x option prints commands and their arguments as they are executed.


The most popular of these options is the -x option.

You can use these options by updating the first line in your script to include one or more of these options. The Bash shell provides some options that can help you in debugging your scripts. This process of finding errors in your script or fixing unexpected behaviors is called debugging. Sometimes it will simply stop because of a syntax error or a typo. Sometimes your script will produce an incorrect result or behave in unintended ways.
#Shell script debugger update
Maybe something isn't working as you initially anticipated and you want to figure out where things are going wrong and how you can update your script so that it performs as expected. If you encounter a bug or an error in one of your scripts, you'll want to see exactly what is happening during the execution of that script.
#Shell script debugger code
Most of the bugs are actually mistakes in the program's code or in its design.
#Shell script debugger software
In this lesson, you will learn about the options built into Bash that will help you find and fix errors in your shell scripts.Ī software bug is an error in a computer program that causes it to produce an unexpected or incorrect result.
