Linux-shell脚本的调试和追踪

shell脚本的语法调试,我们使用bash的相关参数进行调试

sh [参数] 文件名.sh
  • -n 不要执行script,仅查询语法的问题
  • -v 在执行script之前,先将script的内容输出到屏幕上
  • -x 将使用的脚本的内容输出到屏幕,该参数经常被使用
#-v的示例:
[----~]$ sh -v demo.sh module () { eval `/usr/bin/modulecmd bash $*` } #!/bin/bash case $1 in "one") echo "you input number is one" ;; "two") echo "you input number is twp" ;; *) echo "you input number is other" ;; esac you input number is other
#-x的示例:
[--- ~]$ sh -x demo.sh 
+ case $1 in
+ echo 'you input number is other'
you input number is other