本文摘自PHP中文网,作者不言,侵删。
如何调试shell脚本?我们可以在shell脚本中使用“set-xv”命令或在执行脚本时在命令行上使用-xv来调试shell脚本。
通过添加命令来调试Shell脚本:
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 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脚本中添加“set-xv”。只需创建一个shell脚本,如下所示。
1 2 3 4 5 6 7 | $ cat checkdebug2.sh
#!/bin/bash
cd /var/log/
for i in "*.log" ; do
du -sh $i
done
|
执行如下
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash
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
|
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的Linux教程视频栏目!
以上就是如何调试shell脚本?的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
如何在shell脚本中使用逻辑或&和
linux运维之shell变量.md
bash shell:测试文件或目录是否存在
linux shell ftp按照日期去下载文件的方法
shell编程实战之网站文件及数据库文件的备份
linux中的shell命令如何使用
adb shell是什么意思
详细讲解linux shell中的printf的用法
shell编程实战之内存检查超过设定值杀死php-fpm进程
linux默认的shell是什么
更多相关阅读请进入《shell》频道 >>
转载请注明出处:木庄网络博客 » 如何调试shell脚本?