官术网_书友最值得收藏!

Debugging your scripts

With the scripts as simple as we have seen so far, there is little that can go wrong or debug. As the script grows and decision paths are included with conditional statements, we may need to use some level of debugging to analyze the scripts progress better.

Bash provides two options for us, -v and -x.

If we want to look at the verbose output from our script and the detailed information about the way the script is evaluated line by line, we can use the -v option. This can be within the shebang but it is often easier to run the script directly with bash:

$ bash -v $HOME/bin/hello2.sh fred

This is especially useful in this example as we can see how each element of the embedded basename command is processed. The first step is removing the quotes and then the parentheses. Take a look at the following output:

More commonly used is the -x option, which displays the commands as they get executed. Its useful to know the decision branch that has been chosen by the script. The following shows this in use:

$ bash -x $HOME/bin/hello2.sh fred

We again see that the basename is evaluated first, but we do not see the more detailed steps involved in running that command. The screenshot that follows captures the command and output:

主站蜘蛛池模板: 安新县| 鸡西市| 融水| 陵川县| 株洲县| 泾源县| 乌审旗| 万荣县| 河源市| 莱州市| 青河县| 屏山县| 从化市| 福安市| 阿尔山市| 闽侯县| 赤水市| 伊宁县| 万全县| 永修县| 德化县| 六安市| 乌拉特中旗| 邵阳县| 元江| 南昌市| 宿松县| 泸州市| 宜城市| 建平县| 新津县| 达尔| 霍州市| 芜湖县| 淄博市| 霍城县| 弥渡县| 西贡区| 中西区| 宜川县| 六盘水市|