简体   繁体   English

如何使 python 程序在 bash 脚本中循环执行?

[英]How can i make python program to get executed in a loop in bash script?

I have a bash script where to execute the python program within a loop as below.我有一个 bash 脚本,用于在如下循环中执行 python 程序。 I see only once its getting executed with the below script.我只看到它使用下面的脚本执行一次。 The echo statement prints all the filenames in the directory within the loop, whereas the pgm1.py executes only once. echo 语句打印循环内目录中的所有文件名,而 pgm1.py 只执行一次。 Kindly advice what i have to do it here to continuously getting executed for all the files with the directory.请建议我在这里必须做的事情,以不断地为目录中的所有文件执行。 Here is the below code.这是下面的代码。

LOG_DIR="directorypathname"
DT_H=`date '+%Y-%m-%d_%H_%M_%S'`
linkage_path="directoryname" 
yourfilenames=`ls $linkage_path`

for eachfile in $yourfilenames
do
    python3.5 ${CODE_DIR}/pgm1.py ${linkage_path}/${eachfile}  &> ${LOG_DIR}/${DT_H}.log
    echo ${linkage_path}/${eachfile}
done

You got the syntax wrong你语法错误

for eachfile in $yourfilenames ; do
   python3.5 ${CODE_DIR}/pgm1.py ${linkage_path}/${eachfile} &>> \
      ${LOG_DIR}/${DT_H}.log
   echo ${linkage_path}/${eachfile}
   done

That should do the trick这应该够了吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM