• shell脚本调用python脚本的路径问题


    脚本的相互调用中,只有在同一级目录下才可以使用__file__参数去获取路径名,(在shell里使用pwd也同样),否则,使用的就是主文件(最开始运行的脚本程序)的所在位置,是错误路径:一定要注意当期那运行主文件是谁

    shell脚本相互调用时路径也要注意部分命令会使用当前文件路径:参见

    shell脚本里面相互调用时路径不要用pwd获取

    http://blog.csdn.net/longshenlmj/article/details/16887505 

    [deve_test_user@A3-Tracker-redis-deve script]$ vim testobseve.sh

      1 file_path=`dirname $0`
      2 echo $file_path
      3
      4 testfile="$file_path/observereport"
      5 python $testfile/test.py

    test.py:

    import os
    import sys

    file_path=os.path.dirname(os.path.abspath("__file__"))
    print file_path

    文件test.py在/home/www/allyes/mifc/mIFC-BE/current/script/observereport

    是script的下一级目录

    而输出为:

    [deve_test_user@A3-Tracker-redis-deve script]$ sh testobseve.sh
    .
    /home/www/mifc/mIFC-BE/mifc-BE/script

    可以看出 只能输出shell脚本的当前目录了

  • 相关阅读:
    BZOJ 2326 数学作业
    BZOJ 4448 情报传递
    BZOJ 4443 小凸玩矩阵
    BZOJ 1852 最长不下降序列
    BZOJ 4373 算术天才⑨与等差数列
    68285
    65656556
    D. Points in rectangle
    恐怖的怪物
    再战斐波那契
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205559.html
Copyright © 2020-2023  润新知