The general shell script debugging is basically echo to deal with the larger script when, it is more trouble, out of the question, is not very good to locate which line of code problems.
In fact, some of the variables built into the shell can be a good solution to this problem:
$LINENO $FUNCNAME $BASH _lineno These variables record the current execution position of the script and the function being executed. You can specify the man document page.
Instance code: a.sh
Copy Code code as follows:
#!/bin/bash
ABC () {
echo "Wo shi abc ()"
echo "func: $FUNCNAME ln: $LINENO ln2:${bash_lineno[1]} brother: ${funcname[1]}"
}
B.sh:
Copy Code code as follows:
#!/bin/bash
.. /a.sh
Abc
CDF () {
Abc
}
Execution results:
[Root@node2 ~]#./b.sh
[Code]wo shi ABC ()
FUNC:ABC Ln:5 ln2:0 Brother:main
Wo shi abc () FUNC:ABC Ln:5 ln2:9 BROTHER:CDF
I wrote in the b.sh. The CDF function calls the ABC function, see the output difference, we can use these parameters to print out the location of the code error line, and the code error, which function called, and so on ....