zoukankan      html  css  js  c++  java
  • 调试 shell script 方法

    wade@V1088:~$ cat b.sh
    #!/bin/bash dir=`pwd` dir=$dir'/' for f in `ls *.png` do echo $dir$f done

    看每一行代码的执行:

    wade@V1088:~$ bash -x b.sh
    ++ pwd
    + dir=/home/wade
    + dir=/home/wade/
    ++ ls chrome_1407299385726.png chrome_1427299385726.png
    + for f in '`ls *.png`'
    + echo /home/wade/chrome_1407299385726.png
    /home/wade/chrome_1407299385726.png
    + for f in '`ls *.png`'
    + echo /home/wade/chrome_1427299385726.png

    进一步,看具体执行的代码与行号对应:

    wade@V1088:~$ export PS4='+${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]}: '
    wade@V1088:~$ bash -x b.sh
    ++b.sh:2:: pwd
    +b.sh:2:: dir=/home/wade
    +b.sh:3:: dir=/home/wade/
    ++b.sh:8:: ls chrome_1407299385726.png chrome_1427299385726.png
    +b.sh:4:: for f in '`ls *.png`'
    +b.sh:7:: echo /home/wade/chrome_1407299385726.png
    /home/wade/chrome_1407299385726.png
    +b.sh:4:: for f in '`ls *.png`'
    +b.sh:7:: echo /home/wade/chrome_1427299385726.png

    指定脚本的部分去跑详细的行号,其余的忽略:

    wade@V1088:~$ cat b.sh 
    #!/bin/bash
    dir=`pwd`
    dir=$dir'/'
    #this line above won't log out 
    set -x
    for f in `ls *.png`
    do
    
      echo $dir$f
    done
    set +x
    #the follow line won't log out 
    echo 'end'
    abc='new var'

    运行输出:

    wade@V1088:~$ ./b.sh
    ++./b.sh:10:: ls chrome_1407299385726.png chrome_1427299385726.png
    +./b.sh:6:: for f in '`ls *.png`'
    +./b.sh:9:: echo /home/wade/chrome_1407299385726.png
    /home/wade/chrome_1407299385726.png
    +./b.sh:6:: for f in '`ls *.png`'
    +./b.sh:9:: echo /home/wade/chrome_1427299385726.png
    /home/wade/chrome_1427299385726.png
    +./b.sh:11:: set +x
    end
  • 相关阅读:
    试述软件的概念和特点?软件复用的含义?构件包括哪些?
    Spring Security基本用法
    java中跳出循环的方式
    cookie和session区别
    spring中类型注解下的bean的加载顺序
    常见的异常
    aop使用场景
    缓存类似于redis
    旧版redis使用
    获取rdis的几种方式
  • 原文地址:https://www.cnblogs.com/no7dw/p/3923657.html
Copyright © 2011-2022 走看看