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

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:

主站蜘蛛池模板: 丰宁| 天峨县| 汉源县| 清镇市| 德保县| 金华市| 北川| 平南县| 金寨县| 阿克苏市| 株洲县| 阿拉善左旗| 文水县| 工布江达县| 永胜县| 孝义市| 平湖市| 神木县| 肇东市| 山西省| 巫溪县| 离岛区| 苗栗县| 中超| 谷城县| 盐亭县| 广河县| 化德县| 昆山市| SHOW| 通州区| 永平县| 梁平县| 英德市| 行唐县| 策勒县| 绵竹市| 宜兴市| 蓬溪县| 文水县| 临沭县|