6

Linux shell脚本调试技巧

 2 years ago
source link: https://www.linuxzen.com/linux-shelljiao-ben-diao-shi-ji-qiao.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Home Menu

Linux shell脚本调试技巧

Gray King | Tue 17 January 2012

有时候shell脚本不会给予明显的调试信息,而且有时不报错,但是脚本没有达到预期的效果这时候脚本调试就可以帮你准确定位错误.

在脚本的最顶部加上

set -x

开启调试 在脚本的最底部加上

set +x

关闭调试 如果在终端界面下,调试信息过多,调试信息是无法重定向到文件的,所以该怎样查看调试呢,当然这对SecureCRT连接的当然不是问题,但是如果是终端界面的话,可以使用命令

script

然后执行要捕捉内容的命令,完成后通过

exit

退出,当前目录下会生成typescript,通过

more typescript

查看调试命令.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK