脚本调试_sh -x 、set -x

  • sh -x 脚本名.sh 
对整个脚本进行跟踪
 
   
  1. [root@master shellexer]# cat bash.sh
  2. #!/bin/bash
  3. var=$1
  4. echo $var
  5. [root@master shellexer]# sh -x bash.sh hello
  6. + var=hello
  7. + echo hello
  8. hello         #脚本输出结果
  9.  #带+的表示被跟踪的代码

  • set -x
对脚本内部部分代码进行跟踪,被跟踪的代码以set -x开始,与set +x结束

 
    
  1. [root@master shellexer]# cat bash.sh
  2. #!/bin/bash
  3. var=$1
  4. set -x
  5. ceho $var
  6. set +x
  7. echo $var
  8. [root@master shellexer]# sh bash.sh hello
  9. + ceho hello                            #带+的表示被跟踪的代码
  10. bash.sh: line 4: ceho: command not found
  11. + set +x
  12. hello        #脚本输出结果

猜你喜欢

转载自blog.csdn.net/bbbeoy/article/details/80308792
x