You can enable debugging mode within a bash script, say myscript.sh, by adding the following command line:
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:
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.
- 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.
No comments:
Post a Comment