前几天的一篇linux定时删除服务器日志 ,有人读了,私信问题。说我写了脚本了,怎么去调试一下,类似于代码的debug。
那我们今天来聊聊。
执行脚本命令是:
sh 脚本名
bash
sh dele_log2.sh

执行并输出。
Shell 脚本调试选项:
-v(verbose )
告诉 Shell 读取脚本时显示所有行,激活详细模式。
其实就是当命令进行读取时显示输入。
sh -v 脚本名
bash
sh -v dele_log2.sh

在脚本内部增加 set -v

执行sh dele_log2.sh ,和上面的sh -v dele_log2.sh 一样的效果

+v:禁止打印输入
bash
sh +v dele_log2.sh
-n(noexec 或 no ecxecution)
- 指示 Shell 读取所有命令然而不执行它们,这个选项激活语法检查模式。
sh -n 脚本名
bash
sh -n dele_log2.sh

-x(xtrace 或 execution trace )
告诉 Shell 在终端显示所有执行的命令和它们的参数。 这个选项是启用 Shell 跟踪模式。
sh -x 脚本名
bash
sh -x dele_log2.sh

在脚本内部增加 set -x

执行sh dele_log2.sh ,和上面的sh -x dele_log2.sh 一样的效果

+x:禁止调试。
bash
sh +x dele_log2.sh
