【问题标题】:python script has an output, but in a shell for loop it doesn't outputpython脚本有输出,但在shell for循环中它不输出
【发布时间】:2015-02-01 12:21:00
【问题描述】:

我有一个带有两个参数的 python 脚本,当我运行它时,脚本也会按预期输出 3 个新文件:

>>> python importpymol2.py 65_*.pdb BTB_old.pdb

但是当我通过一个也改变目录的shell循环时(脚本在每个目录中):

>>>> for i in *;do current_dir=$PWD; cd $PWD/*;python importpymol2.py 65_*.pdb BTB_old.pdb;cd $current_dir; done

但是,它运行完全正常,只是它不输出文件....我怎样才能让它输出文件?

【问题讨论】:

  • 如果* 有多个匹配项,cd $PWD/* 应该如何工作(或者根本没有循环)。那个 sn-p 真的可以正常工作吗?

标签: python shell for-loop directory output


【解决方案1】:

不要试图 cd 回来。相反,只需在子 shell 中运行:

for i in *; do ( cd $i; python ...; ); done

【讨论】:

    【解决方案2】:

    你的shell命令可能有错别字,试试改成:

    for i in *;do current_dir=$PWD; cd $PWD/$i;python ../importpymol2.py 65_*.pdb BTB_old.pdb;cd $current_dir; done
    

    (我假设 importpymol2.py 位于您的 $PWD 中。)

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 1970-01-01
      相关资源
      最近更新 更多