• 学派吧-由新云网络独家赞助-https://www.sq9.cn。

如何调试shell脚本教程分享

unix admin 5年前 (2019-03-23) 1944次浏览 已收录 0个评论 扫描二维码

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

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

$ cat checkdebug.sh
#!/bin/bash

set -xv  #<< This will enable debugcd /var/log/
for i in "*.log"; do
 du -sh $i
done

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

#sh checkdebug.sh

输出:

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脚本,如下所示。

$ cat checkdebug2.sh
#!/bin/bash

cd /var/log/
for i in "*.log"; do
 du -sh $i
done

执行如下

# sh -xv checkdebug2.sh

输出:

#!/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

本篇文章到这里就已经全部结束了


学派吧 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何调试shell脚本教程分享
喜欢 (0)
[pay@sq9.cn]
分享 (0)
关于作者:
腾讯云-运维运维 QQ 690624
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址