如何调试shell脚本?


本文摘自PHP中文网,作者不言,侵删。

如何调试shell脚本?我们可以在shell脚本中使用“set-xv”命令或在执行脚本时在命令行上使用-xv来调试shell脚本。

通过添加命令来调试Shell脚本:

1

$ cat checkdebug.sh

1

2

3

4

5

6

#!/bin/bash

 

set -xv  #<< This will enable debugcd /var/log/

for i in "*.log"; do

 du -sh $i

done

执行上面的脚本并观察输出:

1

#sh checkdebug.sh

输出:

1

2

3

4

5

6

7

8

9

10

11

12

cd /var/log/

+ cd /var/log/

for i in "*.log"; do

 du -sh $i

done

+ for i in '"*.log"'

+ du -sh boot.log mysqld.log post111.log post1121.log yum.log

0       boot.log

32K     mysqld.log

0       post111.log

0       post1121.log

4.0K    yum.log

使用选项调试shell脚本:

阅读剩余部分

相关阅读 >>

shell编程实战之监控网卡流量

如何在shell脚本中提取文件名和扩展名

shell脚本应该怎么使用?

linux--bash 和 shell讲解

如何在shell脚本中提取文件名和扩展名

shell script到底是什么?怎么使用?

详细讲解linux shell中的printf的用法

通过几个案例掌握shell编程条件分支结构

启动bash shell有哪些方式?

shell判断字符串为空的方法

更多相关阅读请进入《shell》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...