Monday, March 11, 2013

Starting Up the Bash Subshell with the -x Option

You can enable debugging mode within a bash script, say myscript.sh, by adding the following command line:
  • set -x

For example,

$vi myscript.sh 
#!/bin/bash
set -x


Adding "set -x" in the script, it enables the printing of command traces before executing command.  This is equivalent to the long command notation:

  • set -o xtrace

However, there are cases that you cannot modify the bash script itself because of permission or you simply don't want to modify the file.  Then there is another option:

$ bash -x myscript.sh

This will allow you to execute the script with command traces which are good for debugging.

References

  1. Bash Guide for Beginners

No comments:

Post a Comment