我对 shell 脚本还很陌生。如果有人可以提供帮助,我将不胜感激。
我有一个 Fortran 代码,由一个程序和三个子例程组成,这些子例程使用 .txt 文件通过 Linux Ubuntu 终端中的以下命令更正文件的特定行(扩展名为 .pol):
gfortran -c FirstSubroutine.f90
gfortran -c SecondSubroutine.f90
gfortran -c ThirdSubroutine.f90
gfortran FirstSubroutine.o FirstSubroutine.o FirstSubroutine.o MainProgram.f90 -o exeFileName
./exeFileName Path1 .polFileToBeModified Path2
其中Path1是所有输入文件(包括.pol和.txt文件)所在的文件夹,Path2是希望保存所有输出文件的文件夹。
问题是:“我如何编写一个 shell 脚本来为许多输入文件执行此过程?”
最佳答案
你的问题并不完全清楚,但如果你在 Path1 中有一堆文件,你可能只需要:
for file in Path1/*.pol; do ./exeFileName Path1 $file Path2; done
或
for file in Path1/*.pol; do ./exeFileName Path1 ${file#Path1/} Path2; done
取决于您是想要文件的相对路径还是只需要基本名称。
关于linux - 在 Linux 中对多个文件执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47566088/