How to loop over files in directory and change path and add suffix to filename

前端 未结 5 2305
猫巷女王i
猫巷女王i 2020-11-22 06:23

I need to write a script that starts my program with different arguments, but I\'m new to Bash. I start my program with:

./MyProgram.exe Data/data1.txt [Logs/d

5条回答
  •  甜味超标
    2020-11-22 07:05

    Looks like you're trying to execute a windows file (.exe) Surely you ought to be using powershell. Anyway on a Linux bash shell a simple one-liner will suffice.

    [/home/$] for filename in /Data/*.txt; do for i in {0..3}; do ./MyProgam.exe  Data/filenameLogs/$filename_log$i.txt; done done
    

    Or in a bash

    #!/bin/bash
    
    for filename in /Data/*.txt; 
       do
         for i in {0..3}; 
           do ./MyProgam.exe Data/filename.txt Logs/$filename_log$i.txt; 
         done 
     done
    

提交回复
热议问题